aboutsummaryrefslogtreecommitdiff
path: root/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-03-15 09:27:12 +0200
committertranstrike <transtrike@gmail.com>2021-03-15 09:27:12 +0200
commit0161be09312fde634865f110504884119a617d5c (patch)
tree0fa68366edcb024c054f370ecf90f5b66282aae5 /src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
parente3b5757b5a5db2f7874b0924cdd4a22b1a9e1ee2 (diff)
parentac82c773a5ec43c6a59d3d0b7665b67ac9e6bdde (diff)
downloadDevHive-0161be09312fde634865f110504884119a617d5c.tar
DevHive-0161be09312fde634865f110504884119a617d5c.tar.gz
DevHive-0161be09312fde634865f110504884119a617d5c.zip
Fixed to new() where possible and readable
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;
}