From af2a9b9886b429489e4ef4c2467d0e9e40520c12 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 10:59:12 +0200 Subject: Made properties into variables in Web layer tests --- .../DevHive.Web.Tests/CommentController.Tests.cs | 96 +++++++++++----------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'src/Web/DevHive.Web.Tests/CommentController.Tests.cs') diff --git a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs index 7a15d37..3b7f0a9 100644 --- a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs @@ -17,19 +17,19 @@ namespace DevHive.Web.Tests public class CommentControllerTests { const string MESSAGE = "Gosho Trapov"; - private Mock CommentServiceMock { get; set; } - private Mock MapperMock { get; set; } - private Mock JwtServiceMock { get; set; } - private CommentController CommentController { get; set; } + private Mock _commentServiceMock; + private Mock _mapperMock; + private Mock _jwtServiceMock; + private CommentController _commentController; #region Setup [SetUp] public void SetUp() { - this.CommentServiceMock = new Mock(); - this.MapperMock = new Mock(); - this.JwtServiceMock = new Mock(); - this.CommentController = new CommentController(this.CommentServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); + this._commentServiceMock = new Mock(); + this._mapperMock = new Mock(); + this._jwtServiceMock = new Mock(); + this._commentController = new CommentController(this._commentServiceMock.Object, this._mapperMock.Object, this._jwtServiceMock.Object); } #endregion @@ -47,12 +47,12 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createCommentServiceModel); - this.CommentServiceMock.Setup(p => p.AddComment(It.IsAny())).Returns(Task.FromResult(id)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createCommentServiceModel); + this._commentServiceMock.Setup(p => p.AddComment(It.IsAny())).Returns(Task.FromResult(id)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.CommentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; + IActionResult result = this._commentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; Assert.IsInstanceOf(result); @@ -81,12 +81,12 @@ namespace DevHive.Web.Tests string errorMessage = $"Could not create comment!"; - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createCommentServiceModel); - this.CommentServiceMock.Setup(p => p.AddComment(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createCommentServiceModel); + this._commentServiceMock.Setup(p => p.AddComment(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.CommentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; + IActionResult result = this._commentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; Assert.IsInstanceOf(result); @@ -104,10 +104,10 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - IActionResult result = this.CommentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; + IActionResult result = this._commentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; Assert.IsInstanceOf(result); } @@ -127,11 +127,11 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.GetCommentById(It.IsAny())).Returns(Task.FromResult(readCommentServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readCommentWebModel); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.GetCommentById(It.IsAny())).Returns(Task.FromResult(readCommentServiceModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readCommentWebModel); - IActionResult result = this.CommentController.GetCommentById(id).Result; + IActionResult result = this._commentController.GetCommentById(id).Result; Assert.IsInstanceOf(result); @@ -156,12 +156,12 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.CommentServiceMock.Setup(p => p.UpdateComment(It.IsAny())).Returns(Task.FromResult(id)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateCommentServiceModel); + this._commentServiceMock.Setup(p => p.UpdateComment(It.IsAny())).Returns(Task.FromResult(id)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateCommentServiceModel); - IActionResult result = this.CommentController.UpdateComment(Guid.Empty, updateCommentWebModel, null).Result; + IActionResult result = this._commentController.UpdateComment(Guid.Empty, updateCommentWebModel, null).Result; Assert.IsInstanceOf(result); @@ -185,12 +185,12 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.CommentServiceMock.Setup(p => p.UpdateComment(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateCommentServiceModel); + this._commentServiceMock.Setup(p => p.UpdateComment(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateCommentServiceModel); - IActionResult result = this.CommentController.UpdateComment(Guid.Empty, updateCommentWebModel, null).Result; + IActionResult result = this._commentController.UpdateComment(Guid.Empty, updateCommentWebModel, null).Result; Assert.IsInstanceOf(result); BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; @@ -207,10 +207,10 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(false); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(false); // this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - IActionResult result = this.CommentController.UpdateComment(Guid.Empty, updateCommentWebModel, null).Result; + IActionResult result = this._commentController.UpdateComment(Guid.Empty, updateCommentWebModel, null).Result; Assert.IsInstanceOf(result); } @@ -222,11 +222,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.CommentServiceMock.Setup(p => p.DeleteComment(It.IsAny())).Returns(Task.FromResult(true)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._commentServiceMock.Setup(p => p.DeleteComment(It.IsAny())).Returns(Task.FromResult(true)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.CommentController.DeleteComment(id, null).Result; + IActionResult result = this._commentController.DeleteComment(id, null).Result; Assert.IsInstanceOf(result); } @@ -237,11 +237,11 @@ namespace DevHive.Web.Tests string message = "Could not delete Comment"; Guid id = Guid.NewGuid(); - this.CommentServiceMock.Setup(p => p.DeleteComment(It.IsAny())).Returns(Task.FromResult(false)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._commentServiceMock.Setup(p => p.DeleteComment(It.IsAny())).Returns(Task.FromResult(false)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.CommentController.DeleteComment(id, null).Result; + IActionResult result = this._commentController.DeleteComment(id, null).Result; Assert.IsInstanceOf(result); @@ -254,10 +254,10 @@ namespace DevHive.Web.Tests [Test] public void DeleteComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._commentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - IActionResult result = this.CommentController.DeleteComment(Guid.Empty, null).Result; + IActionResult result = this._commentController.DeleteComment(Guid.Empty, null).Result; Assert.IsInstanceOf(result); } -- cgit v1.2.3