aboutsummaryrefslogtreecommitdiff
path: root/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
diff options
context:
space:
mode:
authorKamen Mladenov <kamen.d.mladenov@protonmail.com>2021-03-14 12:14:59 +0200
committerGitHub <noreply@github.com>2021-03-14 12:14:59 +0200
commit432fc5890814596d50fb409a6e5dc952d7bb4836 (patch)
tree05878ec2aeaa6feda4058e494e586ab0e869a63c /src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
parent97459890f8c25b1af2a17109055afea53ee0b280 (diff)
parent10ac1adbf9fbeaca116d3fd356f85dd64c8c2bf8 (diff)
downloadDevHive-432fc5890814596d50fb409a6e5dc952d7bb4836.tar
DevHive-432fc5890814596d50fb409a6e5dc952d7bb4836.tar.gz
DevHive-432fc5890814596d50fb409a6e5dc952d7bb4836.zip
Merge pull request #21 from Team-Kaleidoscope/unit_test_refactoring
Unit test code style refactor
Diffstat (limited to 'src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs')
-rw-r--r--src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs b/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
index 9cbb43b..0aa22bc 100644
--- a/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
+++ b/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
@@ -11,27 +11,25 @@ namespace DevHive.Data.Tests
public class CommentRepositoryTests
{
private const string COMMENT_MESSAGE = "Comment message";
-
- protected DevHiveContext Context { get; set; }
-
- protected CommentRepository CommentRepository { get; set; }
+ private DevHiveContext _context;
+ private CommentRepository _commentRepository;
#region Setups
[SetUp]
public void Setup()
{
- var optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
+ DbContextOptionsBuilder<DevHiveContext> optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
- this.Context = new DevHiveContext(optionsBuilder.Options);
+ this._context = new DevHiveContext(optionsBuilder.Options);
- CommentRepository = new CommentRepository(Context);
+ this._commentRepository = new CommentRepository(this._context);
}
[TearDown]
public void TearDown()
{
- this.Context.Database.EnsureDeleted();
+ this._context.Database.EnsureDeleted();
}
#endregion
@@ -41,7 +39,7 @@ namespace DevHive.Data.Tests
{
Comment comment = await this.AddEntity();
- Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(comment.Creator.Id, comment.TimeCreated);
+ 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");
}
@@ -49,9 +47,9 @@ namespace DevHive.Data.Tests
[Test]
public async Task GetPostByCreatorAndTimeCreatedAsync_ReturnsNull_IfThePostDoesNotExist()
{
- Comment comment = await this.AddEntity();
+ await this.AddEntity();
- Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
+ Comment resultComment = await this._commentRepository.GetCommentByIssuerAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
Assert.IsNull(resultComment, "GetCommentByIssuerAndTimeCreatedAsync does not return null when the comment does not exist");
}
@@ -63,7 +61,7 @@ namespace DevHive.Data.Tests
{
Comment comment = await this.AddEntity();
- bool result = await this.CommentRepository.DoesCommentExist(comment.Id);
+ bool result = await this._commentRepository.DoesCommentExist(comment.Id);
Assert.IsTrue(result, "DoesCommentExist does not return true whenm the Comment exists");
}
@@ -71,7 +69,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task DoesCommentExist_ReturnsFalse_WhenTheCommentDoesNotExist()
{
- bool result = await this.CommentRepository.DoesCommentExist(Guid.Empty);
+ bool result = await this._commentRepository.DoesCommentExist(Guid.Empty);
Assert.IsFalse(result, "DoesCommentExist does not return false whenm the Comment" +
" does not exist");
@@ -79,18 +77,18 @@ namespace DevHive.Data.Tests
#endregion
#region HelperMethods
- private async Task<Comment> AddEntity(string name = COMMENT_MESSAGE)
+ private async Task<Comment> AddEntity()
{
- User creator = new User { Id = Guid.NewGuid() };
- Comment comment = new Comment
+ User creator = new() { Id = Guid.NewGuid() };
+ Comment comment = new()
{
Message = COMMENT_MESSAGE,
Creator = creator,
TimeCreated = DateTime.Now
};
- this.Context.Comments.Add(comment);
- await this.Context.SaveChangesAsync();
+ this._context.Comments.Add(comment);
+ await this._context.SaveChangesAsync();
return comment;
}