diff options
| author | Victor S <57849063+transtrike@users.noreply.github.com> | 2021-02-05 10:54:49 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-05 10:54:49 -0800 |
| commit | f4a70c6430db923af9fa9958a11c2d6612cb52cc (patch) | |
| tree | ca0ea403ba5500df20bc8854ec50529a25c64245 /src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs | |
| parent | 1ccdefdac025b1b986ad2bd0bc3eda7505d6e7c3 (diff) | |
| parent | 2269b5aa6c8d3dcb407c34fa256200bdc573585a (diff) | |
| download | DevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.tar DevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.tar.gz DevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.zip | |
Merge pull request #18 from Team-Kaleidoscope/devv0.1
First stage: Complete. Awaiting further progress...
Diffstat (limited to 'src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs')
| -rw-r--r-- | src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs | 99 |
1 files changed, 99 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..9cbb43b --- /dev/null +++ b/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs @@ -0,0 +1,99 @@ +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.Creator.Id, 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) + { + User creator = new User { Id = Guid.NewGuid() }; + Comment comment = new Comment + { + Message = COMMENT_MESSAGE, + Creator = creator, + TimeCreated = DateTime.Now + }; + + this.Context.Comments.Add(comment); + await this.Context.SaveChangesAsync(); + + return comment; + } + #endregion + } +} |
