aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-26 18:48:49 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-26 18:48:49 +0200
commit7bd33f55cd044fd232f4b574d54ddeacfd6b5003 (patch)
tree4560832464ca90a80a9d0461fd400b4e1560422d /src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs
parent6c9e165cd1be8bb51c60d449b8721095abc14284 (diff)
downloadDevHive-7bd33f55cd044fd232f4b574d54ddeacfd6b5003.tar
DevHive-7bd33f55cd044fd232f4b574d54ddeacfd6b5003.tar.gz
DevHive-7bd33f55cd044fd232f4b574d54ddeacfd6b5003.zip
adding comment repository tests
Diffstat (limited to 'src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs')
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs
new file mode 100644
index 0000000..2a8bb1f
--- /dev/null
+++ b/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Threading.Tasks;
+using DevHive.Data.Models;
+using DevHive.Data.Repositories;
+using Microsoft.EntityFrameworkCore;
+using NUnit.Framework;
+
+namespace DevHive.Data.Tests
+{
+ [TestFixture]
+ public class CommentRepositoryTests
+ {
+ private const string COMMENT_MESSAGE = "Comment message";
+
+ protected DevHiveContext Context { get; set; }
+
+ protected CommentRepository CommentRepository { get; set; }
+
+ #region Setups
+ [SetUp]
+ public void Setup()
+ {
+ var optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
+ .UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
+
+ this.Context = new DevHiveContext(optionsBuilder.Options);
+
+ CommentRepository = new CommentRepository(Context);
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ this.Context.Database.EnsureDeleted();
+ }
+ #endregion
+
+ #region GetCommentByIssuerAndTimeCreatedAsync
+ [Test]
+ public async Task GetCommentByCreatorAndTimeCreatedAsync_ReturnsTheCorrectComment_IfItExists()
+ {
+ Comment comment = await this.AddEntity();
+
+ Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(comment.CreatorId, comment.TimeCreated);
+
+ Assert.AreEqual(comment.Id, resultComment.Id, "GetCommentByIssuerAndTimeCreatedAsync does not return the corect comment when it exists");
+ }
+
+ [Test]
+ public async Task GetPostByCreatorAndTimeCreatedAsync_ReturnsNull_IfThePostDoesNotExist()
+ {
+ Comment comment = await this.AddEntity();
+
+ Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
+
+ Assert.IsNull(resultComment, "GetCommentByIssuerAndTimeCreatedAsync does not return null when the comment does not exist");
+ }
+ #endregion
+
+ #region DoesCommentExist
+ [Test]
+ public async Task DoesCommentExist_ReturnsTrue_WhenTheCommentExists()
+ {
+ Comment comment = await this.AddEntity();
+
+ bool result = await this.CommentRepository.DoesCommentExist(comment.Id);
+
+ Assert.IsTrue(result, "DoesCommentExist does not return true whenm the Comment exists");
+ }
+
+ [Test]
+ public async Task DoesCommentExist_ReturnsFalse_WhenTheCommentDoesNotExist()
+ {
+ bool result = await this.CommentRepository.DoesCommentExist(Guid.Empty);
+
+ Assert.IsFalse(result, "DoesCommentExist does not return false whenm the Comment" +
+ " does not exist");
+ }
+ #endregion
+
+ #region HelperMethods
+ private async Task<Comment> AddEntity(string name = COMMENT_MESSAGE)
+ {
+ Comment comment = new Comment
+ {
+ Message = COMMENT_MESSAGE,
+ CreatorId = Guid.NewGuid(),
+ TimeCreated = DateTime.Now
+ };
+
+ this.Context.Comments.Add(comment);
+ await this.Context.SaveChangesAsync();
+
+ return comment;
+ }
+ #endregion
+ }
+}