diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-14 10:59:12 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-14 10:59:12 +0200 |
| commit | af2a9b9886b429489e4ef4c2467d0e9e40520c12 (patch) | |
| tree | c5c1ae1d87ce0e697762a3afdb73186f53a9e01a /src/Web/DevHive.Web.Tests/PostController.Tests.cs | |
| parent | 662d7838f1cb03ea069a6bf4d2a3f0e0fb8135dd (diff) | |
| download | DevHive-af2a9b9886b429489e4ef4c2467d0e9e40520c12.tar DevHive-af2a9b9886b429489e4ef4c2467d0e9e40520c12.tar.gz DevHive-af2a9b9886b429489e4ef4c2467d0e9e40520c12.zip | |
Made properties into variables in Web layer tests
Diffstat (limited to 'src/Web/DevHive.Web.Tests/PostController.Tests.cs')
| -rw-r--r-- | src/Web/DevHive.Web.Tests/PostController.Tests.cs | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/src/Web/DevHive.Web.Tests/PostController.Tests.cs b/src/Web/DevHive.Web.Tests/PostController.Tests.cs index 438eb80..c2c2fbc 100644 --- a/src/Web/DevHive.Web.Tests/PostController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/PostController.Tests.cs @@ -17,18 +17,18 @@ namespace DevHive.Web.Tests public class PostControllerTests { const string MESSAGE = "Gosho Trapov"; - private Mock<IPostService> PostServiceMock { get; set; } - private Mock<IMapper> MapperMock { get; set; } - private Mock<IJwtService> JwtServiceMock { get; set; } - private PostController PostController { get; set; } + private Mock<IPostService> _postServiceMock; + private Mock<IMapper> _mapperMock; + private Mock<IJwtService> _jwtServiceMock; + private PostController _postController; [SetUp] public void SetUp() { - this.PostServiceMock = new Mock<IPostService>(); - this.MapperMock = new Mock<IMapper>(); - this.JwtServiceMock = new Mock<IJwtService>(); - this.PostController = new PostController(this.PostServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); + this._postServiceMock = new Mock<IPostService>(); + this._mapperMock = new Mock<IMapper>(); + this._jwtServiceMock = new Mock<IJwtService>(); + this._postController = new PostController(this._postServiceMock.Object, this._mapperMock.Object, this._jwtServiceMock.Object); } #region Create @@ -45,12 +45,12 @@ namespace DevHive.Web.Tests }; Guid id = Guid.NewGuid(); - this.MapperMock.Setup(p => p.Map<CreatePostServiceModel>(It.IsAny<CreatePostWebModel>())).Returns(createPostServiceModel); - this.PostServiceMock.Setup(p => p.CreatePost(It.IsAny<CreatePostServiceModel>())).Returns(Task.FromResult(id)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map<CreatePostServiceModel>(It.IsAny<CreatePostWebModel>())).Returns(createPostServiceModel); + this._postServiceMock.Setup(p => p.CreatePost(It.IsAny<CreatePostServiceModel>())).Returns(Task.FromResult(id)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Create(Guid.Empty, createPostWebModel, null).Result; + IActionResult result = this._postController.Create(Guid.Empty, createPostWebModel, null).Result; Assert.IsInstanceOf<OkObjectResult>(result); @@ -79,12 +79,12 @@ namespace DevHive.Web.Tests Guid id = Guid.Empty; string errorMessage = $"Could not create post!"; - this.MapperMock.Setup(p => p.Map<CreatePostServiceModel>(It.IsAny<CreatePostWebModel>())).Returns(createTechnologyServiceModel); - this.PostServiceMock.Setup(p => p.CreatePost(It.IsAny<CreatePostServiceModel>())).Returns(Task.FromResult(id)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map<CreatePostServiceModel>(It.IsAny<CreatePostWebModel>())).Returns(createTechnologyServiceModel); + this._postServiceMock.Setup(p => p.CreatePost(It.IsAny<CreatePostServiceModel>())).Returns(Task.FromResult(id)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Create(Guid.Empty, createTechnologyWebModel, null).Result; + IActionResult result = this._postController.Create(Guid.Empty, createTechnologyWebModel, null).Result; Assert.IsInstanceOf<BadRequestObjectResult>(result); @@ -102,9 +102,9 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this.PostServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false)); + this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false)); - IActionResult result = this.PostController.Create(Guid.NewGuid(), createPostWebModel, null).Result; + IActionResult result = this._postController.Create(Guid.NewGuid(), createPostWebModel, null).Result; Assert.IsInstanceOf<UnauthorizedResult>(result); } @@ -125,10 +125,10 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this.PostServiceMock.Setup(p => p.GetPostById(It.IsAny<Guid>())).Returns(Task.FromResult(readPostServiceModel)); - this.MapperMock.Setup(p => p.Map<ReadPostWebModel>(It.IsAny<ReadPostServiceModel>())).Returns(readPostWebModel); + this._postServiceMock.Setup(p => p.GetPostById(It.IsAny<Guid>())).Returns(Task.FromResult(readPostServiceModel)); + this._mapperMock.Setup(p => p.Map<ReadPostWebModel>(It.IsAny<ReadPostServiceModel>())).Returns(readPostWebModel); - IActionResult result = this.PostController.GetById(id).Result; + IActionResult result = this._postController.GetById(id).Result; Assert.IsInstanceOf<OkObjectResult>(result); @@ -153,12 +153,12 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.PostServiceMock.Setup(p => p.UpdatePost(It.IsAny<UpdatePostServiceModel>())).Returns(Task.FromResult(id)); - this.MapperMock.Setup(p => p.Map<UpdatePostServiceModel>(It.IsAny<UpdatePostWebModel>())).Returns(updatePostServiceModel); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); + this._postServiceMock.Setup(p => p.UpdatePost(It.IsAny<UpdatePostServiceModel>())).Returns(Task.FromResult(id)); + this._mapperMock.Setup(p => p.Map<UpdatePostServiceModel>(It.IsAny<UpdatePostWebModel>())).Returns(updatePostServiceModel); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Update(id, updatePostWebModel, null).Result; + IActionResult result = this._postController.Update(id, updatePostWebModel, null).Result; Assert.IsInstanceOf<OkObjectResult>(result); } @@ -177,12 +177,12 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.PostServiceMock.Setup(p => p.UpdatePost(It.IsAny<UpdatePostServiceModel>())).Returns(Task.FromResult(Guid.Empty)); - this.MapperMock.Setup(p => p.Map<UpdatePostServiceModel>(It.IsAny<UpdatePostWebModel>())).Returns(updatePostServiceModel); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); + this._postServiceMock.Setup(p => p.UpdatePost(It.IsAny<UpdatePostServiceModel>())).Returns(Task.FromResult(Guid.Empty)); + this._mapperMock.Setup(p => p.Map<UpdatePostServiceModel>(It.IsAny<UpdatePostWebModel>())).Returns(updatePostServiceModel); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Update(id, updatePostWebModel, null).Result; + IActionResult result = this._postController.Update(id, updatePostWebModel, null).Result; Assert.IsInstanceOf<BadRequestObjectResult>(result); BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; @@ -199,9 +199,9 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false)); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false)); - IActionResult result = this.PostController.Update(Guid.Empty, updatePostWebModel, null).Result; + IActionResult result = this._postController.Update(Guid.Empty, updatePostWebModel, null).Result; Assert.IsInstanceOf<UnauthorizedResult>(result); } @@ -213,11 +213,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.PostServiceMock.Setup(p => p.DeletePost(It.IsAny<Guid>())).Returns(Task.FromResult(true)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); + this._postServiceMock.Setup(p => p.DeletePost(It.IsAny<Guid>())).Returns(Task.FromResult(true)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Delete(id, null).Result; + IActionResult result = this._postController.Delete(id, null).Result; Assert.IsInstanceOf<OkResult>(result); } @@ -228,11 +228,11 @@ namespace DevHive.Web.Tests string message = "Could not delete Post"; Guid id = Guid.NewGuid(); - this.PostServiceMock.Setup(p => p.DeletePost(It.IsAny<Guid>())).Returns(Task.FromResult(false)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); + this._postServiceMock.Setup(p => p.DeletePost(It.IsAny<Guid>())).Returns(Task.FromResult(false)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny<Guid>(), It.IsAny<string>())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Delete(id, null).Result; + IActionResult result = this._postController.Delete(id, null).Result; Assert.IsInstanceOf<BadRequestObjectResult>(result); @@ -245,9 +245,9 @@ namespace DevHive.Web.Tests [Test] public void DeletePost_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false)); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false)); - IActionResult result = this.PostController.Delete(Guid.Empty, null).Result; + IActionResult result = this._postController.Delete(Guid.Empty, null).Result; Assert.IsInstanceOf<UnauthorizedResult>(result); } |
