From 8adb24d535c54de558cd1278d5e98632bed755e3 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 11:03:25 +0200 Subject: Made properties into variables in Service layer tests --- .../DevHive.Services.Tests/CommentService.Tests.cs | 94 +++++++++++----------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'src/Services/DevHive.Services.Tests/CommentService.Tests.cs') diff --git a/src/Services/DevHive.Services.Tests/CommentService.Tests.cs b/src/Services/DevHive.Services.Tests/CommentService.Tests.cs index 2d3c97a..a73cf90 100644 --- a/src/Services/DevHive.Services.Tests/CommentService.Tests.cs +++ b/src/Services/DevHive.Services.Tests/CommentService.Tests.cs @@ -14,21 +14,21 @@ namespace DevHive.Services.Tests public class CommentServiceTests { private const string MESSAGE = "Gosho Trapov"; - private Mock UserRepositoryMock { get; set; } - private Mock PostRepositoryMock { get; set; } - private Mock CommentRepositoryMock { get; set; } - private Mock MapperMock { get; set; } - private CommentService CommentService { get; set; } + private Mock _userRepositoryMock; + private Mock _postRepositoryMock; + private Mock _commentRepositoryMock; + private Mock _mapperMock; + private CommentService _commentService; #region Setup [SetUp] public void Setup() { - this.UserRepositoryMock = new Mock(); - this.PostRepositoryMock = new Mock(); - this.CommentRepositoryMock = new Mock(); - this.MapperMock = new Mock(); - this.CommentService = new CommentService(this.UserRepositoryMock.Object, this.PostRepositoryMock.Object, this.CommentRepositoryMock.Object, this.MapperMock.Object); + this._userRepositoryMock = new Mock(); + this._postRepositoryMock = new Mock(); + this._commentRepositoryMock = new Mock(); + this._mapperMock = new Mock(); + this._commentService = new CommentService(this._userRepositoryMock.Object, this._postRepositoryMock.Object, this._commentRepositoryMock.Object, this._mapperMock.Object); } #endregion @@ -48,13 +48,13 @@ namespace DevHive.Services.Tests Id = id, }; - _ = this.CommentRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(true)); - _ = this.CommentRepositoryMock.Setup(p => p.GetCommentByIssuerAndTimeCreatedAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(comment)); - _ = this.PostRepositoryMock.Setup(p => p.DoesPostExist(It.IsAny())).Returns(Task.FromResult(true)); - _ = this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(creator)); - _ = this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(comment); + _ = this._commentRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(true)); + _ = this._commentRepositoryMock.Setup(p => p.GetCommentByIssuerAndTimeCreatedAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(comment)); + _ = this._postRepositoryMock.Setup(p => p.DoesPostExist(It.IsAny())).Returns(Task.FromResult(true)); + _ = this._userRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(creator)); + _ = this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(comment); - Guid result = await this.CommentService.AddComment(createCommentServiceModel); + Guid result = await this._commentService.AddComment(createCommentServiceModel); Assert.AreEqual(id, result); } @@ -71,11 +71,11 @@ namespace DevHive.Services.Tests Message = MESSAGE, }; - _ = this.CommentRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(false)); - _ = this.PostRepositoryMock.Setup(p => p.DoesPostExist(It.IsAny())).Returns(Task.FromResult(true)); - _ = this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(comment); + _ = this._commentRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(false)); + _ = this._postRepositoryMock.Setup(p => p.DoesPostExist(It.IsAny())).Returns(Task.FromResult(true)); + _ = this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(comment); - Guid result = await this.CommentService.AddComment(createCommentServiceModel); + Guid result = await this._commentService.AddComment(createCommentServiceModel); Assert.IsTrue(result == Guid.Empty); } @@ -90,7 +90,7 @@ namespace DevHive.Services.Tests Message = MESSAGE }; - Exception ex = Assert.ThrowsAsync(() => this.CommentService.AddComment(createCommentServiceModel), "AddComment does not throw excpeion when the post does not exist"); + Exception ex = Assert.ThrowsAsync(() => this._commentService.AddComment(createCommentServiceModel), "AddComment does not throw excpeion when the post does not exist"); Assert.AreEqual(EXCEPTION_MESSAGE, ex.Message, "Incorecct exception message"); } @@ -116,11 +116,11 @@ namespace DevHive.Services.Tests Id = creatorId, }; - _ = this.CommentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(comment)); - _ = this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); - _ = this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(commentServiceModel); + _ = this._commentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(comment)); + _ = this._userRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); + _ = this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(commentServiceModel); - ReadCommentServiceModel result = await this.CommentService.GetCommentById(Guid.NewGuid()); + ReadCommentServiceModel result = await this._commentService.GetCommentById(Guid.NewGuid()); Assert.AreEqual(MESSAGE, result.Message); } @@ -137,9 +137,9 @@ namespace DevHive.Services.Tests Creator = creator }; - _ = this.CommentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(comment)); + _ = this._commentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(comment)); - Exception ex = Assert.ThrowsAsync(() => this.CommentService.GetCommentById(Guid.NewGuid()), "GetCommentById does not throw exception when the user does not exist"); + Exception ex = Assert.ThrowsAsync(() => this._commentService.GetCommentById(Guid.NewGuid()), "GetCommentById does not throw exception when the user does not exist"); Assert.AreEqual(EXCEPTION_MESSAGE, ex.Message); } @@ -154,10 +154,10 @@ namespace DevHive.Services.Tests Id = creatorId, }; - _ = this.CommentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(null)); - _ = this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); + _ = this._commentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(null)); + _ = this._userRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); - Exception ex = Assert.ThrowsAsync(() => this.CommentService.GetCommentById(Guid.NewGuid())); + Exception ex = Assert.ThrowsAsync(() => this._commentService.GetCommentById(Guid.NewGuid())); Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } @@ -179,12 +179,12 @@ namespace DevHive.Services.Tests NewMessage = MESSAGE }; - _ = this.CommentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(true)); - _ = this.CommentRepositoryMock.Setup(p => p.EditAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - _ = this.CommentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(comment)); - _ = this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(comment); + _ = this._commentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(true)); + _ = this._commentRepositoryMock.Setup(p => p.EditAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + _ = this._commentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(comment)); + _ = this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(comment); - Guid result = await this.CommentService.UpdateComment(updateCommentServiceModel); + Guid result = await this._commentService.UpdateComment(updateCommentServiceModel); Assert.AreEqual(updateCommentServiceModel.CommentId, result); } @@ -202,11 +202,11 @@ namespace DevHive.Services.Tests NewMessage = MESSAGE }; - _ = this.CommentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(true)); - _ = this.CommentRepositoryMock.Setup(p => p.EditAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - _ = this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(comment); + _ = this._commentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(true)); + _ = this._commentRepositoryMock.Setup(p => p.EditAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + _ = this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(comment); - Guid result = await this.CommentService.UpdateComment(updateCommentServiceModel); + Guid result = await this._commentService.UpdateComment(updateCommentServiceModel); Assert.AreEqual(Guid.Empty, result); } @@ -219,9 +219,9 @@ namespace DevHive.Services.Tests { }; - _ = this.CommentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(false)); + _ = this._commentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(false)); - Exception ex = Assert.ThrowsAsync(() => this.CommentService.UpdateComment(updateCommentServiceModel)); + Exception ex = Assert.ThrowsAsync(() => this._commentService.UpdateComment(updateCommentServiceModel)); Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } @@ -236,11 +236,11 @@ namespace DevHive.Services.Tests Guid id = new(); Comment comment = new(); - _ = this.CommentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(true)); - _ = this.CommentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(comment)); - _ = this.CommentRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny())).Returns(Task.FromResult(shouldPass)); + _ = this._commentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(true)); + _ = this._commentRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(comment)); + _ = this._commentRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny())).Returns(Task.FromResult(shouldPass)); - bool result = await this.CommentService.DeleteComment(id); + bool result = await this._commentService.DeleteComment(id); Assert.AreEqual(shouldPass, result); } @@ -251,9 +251,9 @@ namespace DevHive.Services.Tests string exceptionMessage = "Comment does not exist!"; Guid id = new(); - _ = this.CommentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(false)); + _ = this._commentRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny())).Returns(Task.FromResult(false)); - Exception ex = Assert.ThrowsAsync(() => this.CommentService.DeleteComment(id)); + Exception ex = Assert.ThrowsAsync(() => this._commentService.DeleteComment(id)); Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } -- cgit v1.2.3