From f986ca67edd425c32eaec5a20fecdc5786f9d8e3 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 3 Mar 2021 10:27:26 +0200 Subject: Fixing bugs in rating layer --- src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs | 4 ---- src/Web/DevHive.Web/Controllers/RatingController.cs | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs b/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs index 425c3e1..176c099 100644 --- a/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs +++ b/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs @@ -8,10 +8,6 @@ namespace DevHive.Web.Models.Rating { public class UpdateRatingWebModel { - public Guid Id { get; set; } - - public Guid PostId { get; set; } - public bool IsLike { get; set; } } } diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index 5716b85..8d3ac92 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -65,7 +65,7 @@ namespace DevHive.Web.Controllers } [HttpPut] - public async Task UpdateRating(Guid userId, [FromBody] UpdateRatingWebModel updateRatingWebModel, [FromHeader] string authorization) + public async Task UpdateRating(Guid userId, Guid postId, [FromBody] UpdateRatingWebModel updateRatingWebModel, [FromHeader] string authorization) { if (!this._jwtService.ValidateToken(userId, authorization)) return new UnauthorizedResult(); @@ -73,6 +73,7 @@ namespace DevHive.Web.Controllers UpdateRatingServiceModel updateRatingServiceModel = this._mapper.Map(updateRatingWebModel); updateRatingServiceModel.UserId = userId; + updateRatingServiceModel.PostId = postId; ReadRatingServiceModel readRatingServiceModel = await this._rateService.UpdateRating(updateRatingServiceModel); -- cgit v1.2.3 From 4612913c72c3d2b4d3e28629df9f2ed97f0c29a9 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 3 Mar 2021 10:55:28 +0200 Subject: Moved Rating service models outside of Post folder --- .../Post/Rating/CreateRatingServiceModel.cs | 13 ------------- .../Post/Rating/ReadRatingServiceModel.cs | 15 --------------- .../Post/Rating/UpdateRatingServiceModel.cs | 15 --------------- .../Rating/CreateRatingServiceModel.cs | 13 +++++++++++++ .../Rating/ReadRatingServiceModel.cs | 15 +++++++++++++++ .../Rating/UpdateRatingServiceModel.cs | 15 +++++++++++++++ .../Configurations/Mapping/RatingMappings.cs | 2 +- .../DevHive.Services/Interfaces/IRatingService.cs | 2 +- src/Services/DevHive.Services/Services/RatingService.cs | 2 +- .../DevHive.Web/Configurations/Mapping/RatingMappings.cs | 2 +- src/Web/DevHive.Web/Controllers/RatingController.cs | 2 +- 11 files changed, 48 insertions(+), 48 deletions(-) delete mode 100644 src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs delete mode 100644 src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs delete mode 100644 src/Services/DevHive.Services.Models/Post/Rating/UpdateRatingServiceModel.cs create mode 100644 src/Services/DevHive.Services.Models/Rating/CreateRatingServiceModel.cs create mode 100644 src/Services/DevHive.Services.Models/Rating/ReadRatingServiceModel.cs create mode 100644 src/Services/DevHive.Services.Models/Rating/UpdateRatingServiceModel.cs (limited to 'src/Web') diff --git a/src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs deleted file mode 100644 index aaeab73..0000000 --- a/src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Rating -{ - public class CreateRatingServiceModel - { - public Guid UserId { get; set; } - - public Guid PostId { get; set; } - - public bool IsLike { get; set; } - } -} diff --git a/src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs deleted file mode 100644 index 86b4957..0000000 --- a/src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Rating -{ - public class ReadRatingServiceModel - { - public Guid Id { get; set; } - - public Guid PostId { get; set; } - - public Guid UserId { get; set; } - - public bool IsLike { get; set; } - } -} diff --git a/src/Services/DevHive.Services.Models/Post/Rating/UpdateRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Post/Rating/UpdateRatingServiceModel.cs deleted file mode 100644 index 1ea8d8f..0000000 --- a/src/Services/DevHive.Services.Models/Post/Rating/UpdateRatingServiceModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Rating -{ - public class UpdateRatingServiceModel - { - public Guid Id { get; set; } - - public Guid UserId { get; set; } - - public Guid PostId { get; set; } - - public bool IsLike { get; set; } - } -} diff --git a/src/Services/DevHive.Services.Models/Rating/CreateRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Rating/CreateRatingServiceModel.cs new file mode 100644 index 0000000..486e3d2 --- /dev/null +++ b/src/Services/DevHive.Services.Models/Rating/CreateRatingServiceModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace DevHive.Services.Models.Rating +{ + public class CreateRatingServiceModel + { + public Guid UserId { get; set; } + + public Guid PostId { get; set; } + + public bool IsLike { get; set; } + } +} diff --git a/src/Services/DevHive.Services.Models/Rating/ReadRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Rating/ReadRatingServiceModel.cs new file mode 100644 index 0000000..56a5ab0 --- /dev/null +++ b/src/Services/DevHive.Services.Models/Rating/ReadRatingServiceModel.cs @@ -0,0 +1,15 @@ +using System; + +namespace DevHive.Services.Models.Rating +{ + public class ReadRatingServiceModel + { + public Guid Id { get; set; } + + public Guid PostId { get; set; } + + public Guid UserId { get; set; } + + public bool IsLike { get; set; } + } +} diff --git a/src/Services/DevHive.Services.Models/Rating/UpdateRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Rating/UpdateRatingServiceModel.cs new file mode 100644 index 0000000..923e789 --- /dev/null +++ b/src/Services/DevHive.Services.Models/Rating/UpdateRatingServiceModel.cs @@ -0,0 +1,15 @@ +using System; + +namespace DevHive.Services.Models.Rating +{ + public class UpdateRatingServiceModel + { + public Guid Id { get; set; } + + public Guid UserId { get; set; } + + public Guid PostId { get; set; } + + public bool IsLike { get; set; } + } +} diff --git a/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs b/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs index 4534511..9ad5f25 100644 --- a/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs +++ b/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs @@ -1,6 +1,6 @@ using AutoMapper; using DevHive.Data.Models; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; namespace DevHive.Services.Configurations.Mapping { diff --git a/src/Services/DevHive.Services/Interfaces/IRatingService.cs b/src/Services/DevHive.Services/Interfaces/IRatingService.cs index b262f45..be33300 100644 --- a/src/Services/DevHive.Services/Interfaces/IRatingService.cs +++ b/src/Services/DevHive.Services/Interfaces/IRatingService.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using DevHive.Data.Models; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; namespace DevHive.Services.Interfaces { diff --git a/src/Services/DevHive.Services/Services/RatingService.cs b/src/Services/DevHive.Services/Services/RatingService.cs index 6d0d0b9..1f77a6e 100644 --- a/src/Services/DevHive.Services/Services/RatingService.cs +++ b/src/Services/DevHive.Services/Services/RatingService.cs @@ -8,7 +8,7 @@ using AutoMapper; using DevHive.Data.Interfaces; using DevHive.Data.Models; using DevHive.Services.Interfaces; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; namespace DevHive.Services.Services { diff --git a/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs index 23c3eeb..1d731d8 100644 --- a/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs +++ b/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs @@ -1,5 +1,5 @@ using AutoMapper; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; using DevHive.Web.Models.Rating; namespace DevHive.Web.Configurations.Mapping diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index 8d3ac92..c93a56d 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using AutoMapper; using DevHive.Common.Jwt.Interfaces; using DevHive.Services.Interfaces; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; using DevHive.Web.Models.Rating; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -- cgit v1.2.3 From 95693f70a2314eab65ac289580d264fe12c42a06 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 3 Mar 2021 10:56:48 +0200 Subject: Adding authorization to Rating Controller --- src/Web/DevHive.Web/Controllers/RatingController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index c93a56d..8c44243 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Mvc; namespace DevHive.Web.Controllers { [ApiController] - //[Authorize(Roles = "Admin,User")] + [Authorize(Roles = "Admin,User")] [Route("api/[controller]")] public class RatingController { -- cgit v1.2.3 From 6cc1bceebfa1ed01472303db226c000c2345b016 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 3 Mar 2021 10:57:49 +0200 Subject: Removed _userService from RatingController --- src/Web/DevHive.Web/Controllers/RatingController.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index 8c44243..f6ab0c5 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -16,14 +16,12 @@ namespace DevHive.Web.Controllers public class RatingController { private readonly IRatingService _rateService; - private readonly IUserService _userService; private readonly IMapper _mapper; private readonly IJwtService _jwtService; - public RatingController(IRatingService rateService, IUserService userService, IMapper mapper, IJwtService jwtService) + public RatingController(IRatingService rateService, IMapper mapper, IJwtService jwtService) { this._rateService = rateService; - this._userService = userService; this._mapper = mapper; this._jwtService = jwtService; } -- cgit v1.2.3 From b3fd74a4207334b7b31e9450a078bd10437648c3 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 13 Mar 2021 08:46:31 +0200 Subject: Fixed type in delete rating method name in rating controller --- src/Web/DevHive.Web/Controllers/RatingController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index f6ab0c5..7d21795 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -85,7 +85,7 @@ namespace DevHive.Web.Controllers } [HttpDelete] - public async Task DeleteTating(Guid userId, Guid ratingId, [FromHeader] string authorization) + public async Task DeleteRating(Guid userId, Guid ratingId, [FromHeader] string authorization) { if (!this._jwtService.ValidateToken(userId, authorization)) return new UnauthorizedResult(); -- cgit v1.2.3 From b2d6b607a116f1d3d491ac24c484a26f0c956688 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 13 Mar 2021 08:46:50 +0200 Subject: Added tests for rating controller --- .../DevHive.Web.Tests/RatingController.Tests.cs | 257 +++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 src/Web/DevHive.Web.Tests/RatingController.Tests.cs (limited to 'src/Web') diff --git a/src/Web/DevHive.Web.Tests/RatingController.Tests.cs b/src/Web/DevHive.Web.Tests/RatingController.Tests.cs new file mode 100644 index 0000000..dd8954f --- /dev/null +++ b/src/Web/DevHive.Web.Tests/RatingController.Tests.cs @@ -0,0 +1,257 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Common.Jwt.Interfaces; +using DevHive.Services.Interfaces; +using DevHive.Services.Models.Rating; +using DevHive.Web.Controllers; +using DevHive.Web.Models.Rating; +using Microsoft.AspNetCore.Mvc; +using Moq; +using NUnit.Framework; + +namespace DevHive.Web.Tests +{ + [TestFixture] + public class RatingControllerTests + { + private Mock RatingServiceMock { get; set; } + private Mock MapperMock { get; set; } + private Mock JwtServiceMock { get; set; } + private RatingController RatingController { get; set; } + + [SetUp] + public void SetUp() + { + this.RatingServiceMock = new Mock(); + this.MapperMock = new Mock(); + this.JwtServiceMock = new Mock(); + this.RatingController = new RatingController(this.RatingServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); + } + + #region Create + [Test] + public void CreateRating_ReturnsOkObjectResult_WhenRatingIsSuccessfullyCreated() + { + Guid postId = Guid.NewGuid(); + CreateRatingWebModel createRatingWebModel = new CreateRatingWebModel + { + PostId = postId, + IsLike = true + }; + CreateRatingServiceModel createRatingServiceModel = new CreateRatingServiceModel + { + PostId = postId, + IsLike = true + }; + Guid ratingId = Guid.NewGuid(); + + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createRatingServiceModel); + this.RatingServiceMock.Setup(p => p.RatePost(It.IsAny())).Returns(Task.FromResult(ratingId)); + + IActionResult result = this.RatingController.RatePost(Guid.Empty, createRatingWebModel, String.Empty).Result; + + Assert.IsInstanceOf(result); + + var splitted = (result as OkObjectResult).Value + .ToString() + .Split('{', '}', '=', ' ') + .Where(x => !string.IsNullOrEmpty(x)) + .ToArray(); + + Guid resultId = Guid.Parse(splitted[1]); + + Assert.AreEqual(ratingId, resultId); + } + + [Test] + public void CreateRating_ReturnsBadRequestResult_WhenRatingIsNotSuccessfullyCreated() + { + Guid postId = Guid.NewGuid(); + CreateRatingWebModel createRatingWebModel = new CreateRatingWebModel + { + PostId = postId, + IsLike = true + }; + CreateRatingServiceModel createRatingServiceModel = new CreateRatingServiceModel + { + PostId = postId, + IsLike = true + }; + Guid ratingId = Guid.NewGuid(); + + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createRatingServiceModel); + this.RatingServiceMock.Setup(p => p.RatePost(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); + + IActionResult result = this.RatingController.RatePost(Guid.Empty, createRatingWebModel, String.Empty).Result; + + Assert.IsInstanceOf(result); + } + #endregion + + #region Read + [Test] + public void GetRatingById_ReturnsTheRating_WhenItExists() + { + Guid id = Guid.NewGuid(); + Guid userId = Guid.NewGuid(); + Guid postId = Guid.NewGuid(); + ReadRatingWebModel readRatingWebModel = new ReadRatingWebModel + { + Id = id, + UserId = userId, + PostId = postId, + IsLike = true + }; + ReadRatingServiceModel readRatingServiceModel = new ReadRatingServiceModel + { + Id = id, + UserId = userId, + PostId = postId, + IsLike = true + }; + + this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingServiceModel); + this.RatingServiceMock.Setup(p => p.GetRatingById(It.IsAny())).Returns(Task.FromResult(readRatingServiceModel)); + + IActionResult result = this.RatingController.GetRatingById(id).Result; + + Assert.IsInstanceOf(result); + } + + [Test] + public void GetRatingByUserAndPost_ReturnsTheRating_WhenItExists() + { + Guid id = Guid.NewGuid(); + Guid userId = Guid.NewGuid(); + Guid postId = Guid.NewGuid(); + ReadRatingWebModel readRatingWebModel = new ReadRatingWebModel + { + Id = id, + UserId = userId, + PostId = postId, + IsLike = true + }; + ReadRatingServiceModel readRatingServiceModel = new ReadRatingServiceModel + { + Id = id, + UserId = userId, + PostId = postId, + IsLike = true + }; + + this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingServiceModel); + this.RatingServiceMock.Setup(p => p.GetRatingByPostAndUser(It.IsAny(), It.IsAny())).Returns(Task.FromResult(readRatingServiceModel)); + + IActionResult result = this.RatingController.GetRatingByUserAndPost(userId, postId).Result; + + Assert.IsInstanceOf(result); + } + + #endregion + + #region Update + [Test] + public void Update_ShouldReturnOkResult_WhenRatingIsUpdatedSuccessfully() + { + Guid id = Guid.NewGuid(); + Guid userId = Guid.NewGuid(); + Guid postId = Guid.NewGuid(); + UpdateRatingWebModel updateRatingWebModel = new UpdateRatingWebModel + { + IsLike = true + }; + UpdateRatingServiceModel updateRatingServiceModel = new UpdateRatingServiceModel + { + Id = id, + UserId = userId, + PostId = postId, + IsLike = true + }; + ReadRatingWebModel readRatingWebModel = new ReadRatingWebModel + { + Id = id, + UserId = userId, + PostId = postId, + IsLike = true + }; + ReadRatingServiceModel readRatingServiceModel = new ReadRatingServiceModel + { + Id = id, + UserId = userId, + PostId = postId, + IsLike = true + }; + + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRatingServiceModel); + this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingWebModel); + this.RatingServiceMock.Setup(p => p.UpdateRating(It.IsAny())).Returns(Task.FromResult(readRatingServiceModel)); + + IActionResult result = this.RatingController.UpdateRating(userId, postId, updateRatingWebModel, String.Empty).Result; + + Assert.IsInstanceOf(result); + } + + [Test] + public void Update_ShouldReturnBadObjectResult_WhenLanguageIsNotUpdatedSuccessfully() + { + Guid id = Guid.NewGuid(); + UpdateRatingWebModel updateRatingWebModel = new UpdateRatingWebModel + { + IsLike = true + }; + UpdateRatingServiceModel updateRatingServiceModel = new UpdateRatingServiceModel + { + Id = id, + IsLike = true + }; + + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRatingServiceModel); + this.RatingServiceMock.Setup(p => p.UpdateRating(It.IsAny())).Returns(Task.FromResult(null)); + + IActionResult result = this.RatingController.UpdateRating(Guid.Empty, Guid.Empty, updateRatingWebModel, String.Empty).Result; + + Assert.IsInstanceOf(result); + } + #endregion + + #region Delete + [Test] + public void Delete_ReturnsOkResult_WhenRatingIsDeletedSuccessfully() + { + Guid id = Guid.NewGuid(); + + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this.RatingServiceMock.Setup(p => p.DeleteRating(It.IsAny())).Returns(Task.FromResult(true)); + + IActionResult result = this.RatingController.DeleteRating(Guid.Empty, Guid.Empty, String.Empty).Result; + + Assert.IsInstanceOf(result); + } + + [Test] + public void Delete_ReturnsBadRequestObjectResult_WhenRatingIsNotDeletedSuccessfully() + { + string message = "Could not delete Rating"; + Guid id = Guid.NewGuid(); + + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this.RatingServiceMock.Setup(p => p.DeleteRating(It.IsAny())).Returns(Task.FromResult(false)); + + IActionResult result = this.RatingController.DeleteRating(Guid.Empty, Guid.Empty, String.Empty).Result; + + Assert.IsInstanceOf(result); + + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultModel = badRequestObjectResult.Value.ToString(); + + Assert.AreEqual(message, resultModel); + } + #endregion + } +} -- cgit v1.2.3 From 441f04790659a439c0054b7b06130d14cc2eb90b Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 13 Mar 2021 10:01:23 +0200 Subject: Technology xml comments added; Needs finish --- .../Controllers/TechnologyController.cs | 5 +++ src/Web/DevHive.Web/Controllers/UserController.cs | 52 ++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web/Controllers/TechnologyController.cs b/src/Web/DevHive.Web/Controllers/TechnologyController.cs index e507899..ba3f04a 100644 --- a/src/Web/DevHive.Web/Controllers/TechnologyController.cs +++ b/src/Web/DevHive.Web/Controllers/TechnologyController.cs @@ -23,6 +23,11 @@ namespace DevHive.Web.Controllers this._technologyMapper = technologyMapper; } + /// + /// Create a new technology, so users can have a choice. Admin only! + /// + /// Data for the new technology + /// [HttpPost] [Authorize(Roles = "Admin")] public async Task Create([FromBody] CreateTechnologyWebModel createTechnologyWebModel) diff --git a/src/Web/DevHive.Web/Controllers/UserController.cs b/src/Web/DevHive.Web/Controllers/UserController.cs index b01ecc1..86076e5 100644 --- a/src/Web/DevHive.Web/Controllers/UserController.cs +++ b/src/Web/DevHive.Web/Controllers/UserController.cs @@ -8,12 +8,16 @@ using Microsoft.AspNetCore.Mvc; using DevHive.Common.Models.Identity; using DevHive.Services.Interfaces; using DevHive.Common.Jwt.Interfaces; -using DevHive.Web.Models.Attributes; +using NSwag.Annotations; namespace DevHive.Web.Controllers { + /// + /// All endpoints for integration with the User + /// [ApiController] [Route("/api/[controller]")] + [OpenApiController("User Controller")] public class UserController : ControllerBase { private readonly IUserService _userService; @@ -28,9 +32,15 @@ namespace DevHive.Web.Controllers } #region Authentication + /// + /// Login endpoint for the DevHive Social Platform + /// + /// Login model with username and password + /// A JWT Token for further validation [HttpPost] - [Route("Login")] [AllowAnonymous] + [Route("Login")] + [OpenApiTags("Authorization")] public async Task Login([FromBody] LoginWebModel loginModel) { LoginServiceModel loginServiceModel = this._userMapper.Map(loginModel); @@ -41,9 +51,15 @@ namespace DevHive.Web.Controllers return new OkObjectResult(tokenWebModel); } + /// + /// Register a new User in the DevHive Social Platform + /// + /// Register model with the new data to provide + /// A JWT Token for further validation [HttpPost] - [Route("Register")] [AllowAnonymous] + [Route("Register")] + [OpenApiTag("Authorization")] public async Task Register([FromBody] RegisterWebModel registerModel) { RegisterServiceModel registerServiceModel = this._userMapper.Map(registerModel); @@ -56,6 +72,12 @@ namespace DevHive.Web.Controllers #endregion #region Read + /// + /// Get a User's information using the Guid + /// + /// User's Guid + /// The JWT Token, contained in the header and used for validation + /// A full User's read model [HttpGet] [Authorize(Roles = "User,Admin")] public async Task GetById(Guid id, [FromHeader] string authorization) @@ -69,6 +91,11 @@ namespace DevHive.Web.Controllers return new OkObjectResult(userWebModel); } + /// + /// Get a User's profile using his username. Does NOT require authorization + /// + /// User's username + /// A trimmed version of the full User's read model [HttpGet] [Route("GetUser")] [AllowAnonymous] @@ -82,6 +109,13 @@ namespace DevHive.Web.Controllers #endregion #region Update + /// + /// Full update on User's data. A PUSTINQK can only edit his account + /// + /// The User's Guid + /// A full User update model + /// The JWT Token, contained in the header and used for validation + /// A full User's read model [HttpPut] [Authorize(Roles = "User,Admin")] public async Task Update(Guid id, [FromBody] UpdateUserWebModel updateUserWebModel, [FromHeader] string authorization) @@ -100,6 +134,12 @@ namespace DevHive.Web.Controllers #endregion #region Delete + /// + /// Delete a User with his Id. A PUSTINQK can only delete his account. An Admin can delete all accounts + /// + /// The User's Guid + /// The JWT Token, contained in the header and used for validation + /// Ok, BadRequest or Unauthorized [HttpDelete] [Authorize(Roles = "User,Admin")] public async Task Delete(Guid id, [FromHeader] string authorization) @@ -115,7 +155,13 @@ namespace DevHive.Web.Controllers } #endregion + /// + /// We don't talk about that, NIGGA! + /// + /// + /// [HttpPost] + [OpenApiIgnore] [Authorize(Roles = "User,Admin")] [Route("SuperSecretPromotionToAdmin")] public async Task SuperSecretPromotionToAdmin(Guid userId) -- cgit v1.2.3 From 93ded2b68a31fc9da643ac65955219e4f306ab82 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 13 Mar 2021 11:44:01 +0200 Subject: XML Docs on all controllers --- .../DevHive.Web/Controllers/CommentController.cs | 38 +++++++++++++++++++--- src/Web/DevHive.Web/Controllers/FeedController.cs | 15 +++++++++ .../DevHive.Web/Controllers/LanguageController.cs | 32 ++++++++++++++++-- src/Web/DevHive.Web/Controllers/PostController.cs | 34 +++++++++++++++++-- .../Controllers/ProfilePictureController.cs | 18 +++++++++- src/Web/DevHive.Web/Controllers/RoleController.cs | 24 ++++++++++++++ .../Controllers/TechnologyController.cs | 25 +++++++++++++- src/Web/DevHive.Web/Controllers/UserController.cs | 6 ++-- src/Web/DevHive.Web/DevHive.Web.csproj | 5 ++- 9 files changed, 181 insertions(+), 16 deletions(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web/Controllers/CommentController.cs b/src/Web/DevHive.Web/Controllers/CommentController.cs index 1722801..8fa3577 100644 --- a/src/Web/DevHive.Web/Controllers/CommentController.cs +++ b/src/Web/DevHive.Web/Controllers/CommentController.cs @@ -10,6 +10,9 @@ using DevHive.Common.Jwt.Interfaces; namespace DevHive.Web.Controllers { + /// + /// All endpoints for interacting with the comments layer + /// [ApiController] [Route("/api/[controller]")] [Authorize(Roles = "User,Admin")] @@ -26,6 +29,13 @@ namespace DevHive.Web.Controllers this._jwtService = jwtService; } + /// + /// Create a comment and attach it to a post + /// + /// The useer's Id + /// The new comment's parametars + /// JWT Bearer token + /// The comment's Id [HttpPost] public async Task AddComment(Guid userId, [FromBody] CreateCommentWebModel createCommentWebModel, [FromHeader] string authorization) { @@ -46,16 +56,28 @@ namespace DevHive.Web.Controllers new OkObjectResult(new { Id = id }); } + /// + /// Query comment's data by it's Id + /// + /// The comment's Id + /// Full data model of the comment [HttpGet] [AllowAnonymous] - public async Task GetCommentById(Guid id) + public async Task GetCommentById(Guid commentId) { - ReadCommentServiceModel readCommentServiceModel = await this._commentService.GetCommentById(id); + ReadCommentServiceModel readCommentServiceModel = await this._commentService.GetCommentById(commentId); ReadCommentWebModel readCommentWebModel = this._commentMapper.Map(readCommentServiceModel); return new OkObjectResult(readCommentWebModel); } + /// + /// Update comment's parametars. Comment creator only! + /// + /// The comment creator's Id + /// New comment's parametars + /// JWT Bearer token + /// Ok result [HttpPut] public async Task UpdateComment(Guid userId, [FromBody] UpdateCommentWebModel updateCommentWebModel, [FromHeader] string authorization) { @@ -73,13 +95,19 @@ namespace DevHive.Web.Controllers new OkObjectResult(new { Id = id }); } + /// + /// Delete a comment. Comment creator only! + /// + /// Comment's Id + /// JWT Bearer token + /// Ok result [HttpDelete] - public async Task DeleteComment(Guid id, [FromHeader] string authorization) + public async Task DeleteComment(Guid commentId, [FromHeader] string authorization) { - if (!await this._commentService.ValidateJwtForComment(id, authorization)) + if (!await this._commentService.ValidateJwtForComment(commentId, authorization)) return new UnauthorizedResult(); - return await this._commentService.DeleteComment(id) ? + return await this._commentService.DeleteComment(commentId) ? new OkResult() : new BadRequestObjectResult("Could not delete Comment"); } diff --git a/src/Web/DevHive.Web/Controllers/FeedController.cs b/src/Web/DevHive.Web/Controllers/FeedController.cs index abca3e4..37532a9 100644 --- a/src/Web/DevHive.Web/Controllers/FeedController.cs +++ b/src/Web/DevHive.Web/Controllers/FeedController.cs @@ -10,6 +10,9 @@ using Microsoft.AspNetCore.Mvc; namespace DevHive.Web.Controllers { + /// + /// All endpoints for interacting with the feed layer + /// [ApiController] [Route("/api/[controller]")] [Authorize(Roles = "User,Admin")] @@ -24,6 +27,12 @@ namespace DevHive.Web.Controllers this._mapper = mapper; } + /// + /// Query posts for user's feed + /// + /// The user's Id, whose feed is begin queried + /// Page parametars + /// A page of the feed [HttpPost] [Route("GetPosts")] public async Task GetPosts(Guid userId, [FromBody] GetPageWebModel getPageWebModel) @@ -37,6 +46,12 @@ namespace DevHive.Web.Controllers return new OkObjectResult(readPageWebModel); } + /// + /// Query a user profile's posts + /// + /// The user's username, whose posts are being queried + /// Page parametars + /// A page of the user's posts [HttpPost] [Route("GetUserPosts")] [AllowAnonymous] diff --git a/src/Web/DevHive.Web/Controllers/LanguageController.cs b/src/Web/DevHive.Web/Controllers/LanguageController.cs index 5b0d5de..665fb66 100644 --- a/src/Web/DevHive.Web/Controllers/LanguageController.cs +++ b/src/Web/DevHive.Web/Controllers/LanguageController.cs @@ -10,6 +10,9 @@ using Microsoft.AspNetCore.Mvc; namespace DevHive.Web.Controllers { + /// + /// All endpoints for interacting with the language layer + /// [ApiController] [Route("/api/[controller]")] public class LanguageController @@ -23,6 +26,11 @@ namespace DevHive.Web.Controllers this._languageMapper = mapper; } + /// + /// Create a new language, so users can have a choice. Admin only! + /// + /// The new language's parametars + /// The new language's Id [HttpPost] [Authorize(Roles = "Admin")] public async Task Create([FromBody] CreateLanguageWebModel createLanguageWebModel) @@ -36,6 +44,11 @@ namespace DevHive.Web.Controllers new OkObjectResult(new { Id = id }); } + /// + /// Query full language data by Id + /// + /// The language's Id + /// Full language data [HttpGet] [AllowAnonymous] public async Task GetById(Guid id) @@ -46,6 +59,10 @@ namespace DevHive.Web.Controllers return new OkObjectResult(languageWebModel); } + /// + /// Query all languages in the database + /// + /// All languages in the database [HttpGet] [Route("GetLanguages")] [Authorize(Roles = "User,Admin")] @@ -57,6 +74,12 @@ namespace DevHive.Web.Controllers return new OkObjectResult(languageWebModels); } + /// + /// Alter language's properties. Admin only! + /// + /// The language's Id + /// The langauge's new parametars + /// Ok result [HttpPut] [Authorize(Roles = "Admin")] public async Task Update(Guid id, [FromBody] UpdateLanguageWebModel updateModel) @@ -72,11 +95,16 @@ namespace DevHive.Web.Controllers return new OkResult(); } + /// + /// Delete a language. Admin only! + /// + /// The language's Id + /// Ok result [HttpDelete] [Authorize(Roles = "Admin")] - public async Task Delete(Guid id) + public async Task Delete(Guid langaugeId) { - bool result = await this._languageService.DeleteLanguage(id); + bool result = await this._languageService.DeleteLanguage(langaugeId); if (!result) return new BadRequestObjectResult("Could not delete Language"); diff --git a/src/Web/DevHive.Web/Controllers/PostController.cs b/src/Web/DevHive.Web/Controllers/PostController.cs index 309070c..44b291d 100644 --- a/src/Web/DevHive.Web/Controllers/PostController.cs +++ b/src/Web/DevHive.Web/Controllers/PostController.cs @@ -10,6 +10,9 @@ using DevHive.Common.Jwt.Interfaces; namespace DevHive.Web.Controllers { + /// + /// All endpoints for interacting with the post layer + /// [ApiController] [Route("/api/[controller]")] [Authorize(Roles = "User,Admin")] @@ -27,6 +30,13 @@ namespace DevHive.Web.Controllers } #region Create + /// + /// Create a new post + /// + /// The user's Id + /// The new post's data + /// JWT Bearer token + /// New post's Id [HttpPost] public async Task Create(Guid userId, [FromForm] CreatePostWebModel createPostWebModel, [FromHeader] string authorization) { @@ -46,6 +56,11 @@ namespace DevHive.Web.Controllers #endregion #region Read + /// + /// Query full post's data by it's Id + /// + /// The post's Id + /// Full data model of the post [HttpGet] [AllowAnonymous] public async Task GetById(Guid id) @@ -58,6 +73,13 @@ namespace DevHive.Web.Controllers #endregion #region Update + /// + /// Update post's data. Creator only! + /// + /// The post creator's Id + /// The new params of the post + /// JWT Bearer token + /// The post's Id [HttpPut] public async Task Update(Guid userId, [FromForm] UpdatePostWebModel updatePostWebModel, [FromHeader] string authorization) { @@ -80,13 +102,19 @@ namespace DevHive.Web.Controllers #endregion #region Delete + /// + /// Delete a post. Creator only! + /// + /// Post's Id + /// JWT Bearer token + /// Ok result [HttpDelete] - public async Task Delete(Guid id, [FromHeader] string authorization) + public async Task Delete(Guid postId, [FromHeader] string authorization) { - if (!await this._postService.ValidateJwtForPost(id, authorization)) + if (!await this._postService.ValidateJwtForPost(postId, authorization)) return new UnauthorizedResult(); - return await this._postService.DeletePost(id) ? + return await this._postService.DeletePost(postId) ? new OkResult() : new BadRequestObjectResult("Could not delete Post"); } diff --git a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs index d3971ff..2eec99e 100644 --- a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs +++ b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs @@ -1,16 +1,32 @@ using System; using System.Threading.Tasks; -using DevHive.Services.Models.User; using DevHive.Web.Models.User; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace DevHive.Web.Controllers { + /// + /// All endpoints for interacting with the profile picture layer + /// [ApiController] [Route("api/[controller]")] public class ProfilePictureController { + // private readonly ProfilePictureService _profilePictureService; + + // public ProfilePictureController(ProfilePictureService profilePictureService) + // { + // this._profilePictureService = profilePictureService; + // } + + /// + /// Alter the profile picture of a user + /// + /// The user's Id + /// The new profile picture + /// JWT Bearer Token + /// ??? [HttpPut] [Route("ProfilePicture")] [Authorize(Roles = "User,Admin")] diff --git a/src/Web/DevHive.Web/Controllers/RoleController.cs b/src/Web/DevHive.Web/Controllers/RoleController.cs index 1465795..ebb305e 100644 --- a/src/Web/DevHive.Web/Controllers/RoleController.cs +++ b/src/Web/DevHive.Web/Controllers/RoleController.cs @@ -9,6 +9,9 @@ using Microsoft.AspNetCore.Authorization; namespace DevHive.Web.Controllers { + /// + /// All endpoints for interacting with the roles layer + /// [ApiController] [Route("/api/[controller]")] public class RoleController @@ -22,6 +25,11 @@ namespace DevHive.Web.Controllers this._roleMapper = mapper; } + /// + /// Create a new role for the roles hierarchy. Admin only! + /// + /// The new role's parametars + /// The new role's Id [HttpPost] [Authorize(Roles = "Admin")] public async Task Create([FromBody] CreateRoleWebModel createRoleWebModel) @@ -36,6 +44,11 @@ namespace DevHive.Web.Controllers new OkObjectResult(new { Id = id }); } + /// + /// Get a role's full data, querying it by it's Id + /// + /// The role's Id + /// Full info of the role [HttpGet] [Authorize(Roles = "User,Admin")] public async Task GetById(Guid id) @@ -46,6 +59,12 @@ namespace DevHive.Web.Controllers return new OkObjectResult(roleWebModel); } + /// + /// Update a role's parametars. Admin only! + /// + /// The role's Id + /// The new parametrats for that role + /// Ok result [HttpPut] [Authorize(Roles = "Admin")] public async Task Update(Guid id, [FromBody] UpdateRoleWebModel updateRoleWebModel) @@ -62,6 +81,11 @@ namespace DevHive.Web.Controllers return new OkResult(); } + /// + /// Delete a role. Admin only! + /// + /// The role's Id + /// Ok result [HttpDelete] [Authorize(Roles = "Admin")] public async Task Delete(Guid id) diff --git a/src/Web/DevHive.Web/Controllers/TechnologyController.cs b/src/Web/DevHive.Web/Controllers/TechnologyController.cs index ba3f04a..ecf2bd7 100644 --- a/src/Web/DevHive.Web/Controllers/TechnologyController.cs +++ b/src/Web/DevHive.Web/Controllers/TechnologyController.cs @@ -10,6 +10,9 @@ using Microsoft.AspNetCore.Mvc; namespace DevHive.Web.Controllers { + /// + /// All endpoints for interacting with the technology layer + /// [ApiController] [Route("/api/[controller]")] public class TechnologyController @@ -27,7 +30,7 @@ namespace DevHive.Web.Controllers /// Create a new technology, so users can have a choice. Admin only! /// /// Data for the new technology - /// + /// The new technology's Id [HttpPost] [Authorize(Roles = "Admin")] public async Task Create([FromBody] CreateTechnologyWebModel createTechnologyWebModel) @@ -41,6 +44,11 @@ namespace DevHive.Web.Controllers new OkObjectResult(new { Id = id }); } + /// + /// Get technology's data by it's Id + /// + /// The technology's Id + /// The technology's full data [HttpGet] [AllowAnonymous] public async Task GetById(Guid id) @@ -51,6 +59,10 @@ namespace DevHive.Web.Controllers return new OkObjectResult(readTechnologyWebModel); } + /// + /// Get all technologies from our database + /// + /// All technologies [HttpGet] [Route("GetTechnologies")] [Authorize(Roles = "User,Admin")] @@ -62,6 +74,12 @@ namespace DevHive.Web.Controllers return new OkObjectResult(languageWebModels); } + /// + /// Alter a technology's parameters. Admin only! + /// + /// Technology's Id + /// The new parametars + /// Ok result [HttpPut] [Authorize(Roles = "Admin")] public async Task Update(Guid id, [FromBody] UpdateTechnologyWebModel updateModel) @@ -77,6 +95,11 @@ namespace DevHive.Web.Controllers return new OkResult(); } + /// + /// Delete a etchnology from the database. Admin only! + /// + /// The technology's Id + /// Ok result [HttpDelete] [Authorize(Roles = "Admin")] public async Task Delete(Guid id) diff --git a/src/Web/DevHive.Web/Controllers/UserController.cs b/src/Web/DevHive.Web/Controllers/UserController.cs index 86076e5..4d01447 100644 --- a/src/Web/DevHive.Web/Controllers/UserController.cs +++ b/src/Web/DevHive.Web/Controllers/UserController.cs @@ -75,7 +75,7 @@ namespace DevHive.Web.Controllers /// /// Get a User's information using the Guid /// - /// User's Guid + /// User's Id /// The JWT Token, contained in the header and used for validation /// A full User's read model [HttpGet] @@ -112,7 +112,7 @@ namespace DevHive.Web.Controllers /// /// Full update on User's data. A PUSTINQK can only edit his account /// - /// The User's Guid + /// The User's Id /// A full User update model /// The JWT Token, contained in the header and used for validation /// A full User's read model @@ -137,7 +137,7 @@ namespace DevHive.Web.Controllers /// /// Delete a User with his Id. A PUSTINQK can only delete his account. An Admin can delete all accounts /// - /// The User's Guid + /// The User's Id /// The JWT Token, contained in the header and used for validation /// Ok, BadRequest or Unauthorized [HttpDelete] diff --git a/src/Web/DevHive.Web/DevHive.Web.csproj b/src/Web/DevHive.Web/DevHive.Web.csproj index 38f21e6..39322ae 100644 --- a/src/Web/DevHive.Web/DevHive.Web.csproj +++ b/src/Web/DevHive.Web/DevHive.Web.csproj @@ -25,6 +25,9 @@ + + + @@ -32,4 +35,4 @@ - + \ No newline at end of file -- cgit v1.2.3 From f14ed20bf06cdeee8ce71ee39756360c43c29df1 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 13 Mar 2021 15:53:48 +0200 Subject: Updated controller tests to mock jwt service, removed profile picture tests from user controller, as that is in it's own layer --- .../DevHive.Web.Tests/CommentController.Tests.cs | 19 +++++++-- src/Web/DevHive.Web.Tests/PostController.Tests.cs | 11 +++++- src/Web/DevHive.Web.Tests/UserController.Tests.cs | 46 +++++----------------- 3 files changed, 35 insertions(+), 41 deletions(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs index 7860f3c..7a15d37 100644 --- a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Threading.Tasks; using AutoMapper; +using DevHive.Common.Jwt.Interfaces; using DevHive.Services.Interfaces; using DevHive.Services.Models.Comment; using DevHive.Web.Controllers; @@ -12,12 +13,13 @@ using NUnit.Framework; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] 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; } #region Setup @@ -26,7 +28,8 @@ namespace DevHive.Web.Tests { this.CommentServiceMock = new Mock(); this.MapperMock = new Mock(); - this.CommentController = new CommentController(this.CommentServiceMock.Object, this.MapperMock.Object); + this.JwtServiceMock = new Mock(); + this.CommentController = new CommentController(this.CommentServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); } #endregion @@ -46,6 +49,7 @@ namespace DevHive.Web.Tests 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; @@ -79,6 +83,7 @@ namespace DevHive.Web.Tests 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; @@ -99,6 +104,7 @@ 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)); IActionResult result = this.CommentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; @@ -121,6 +127,7 @@ 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); @@ -150,6 +157,7 @@ namespace DevHive.Web.Tests }; 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); @@ -178,6 +186,7 @@ namespace DevHive.Web.Tests }; 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); @@ -198,7 +207,8 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - 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(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; @@ -213,6 +223,7 @@ 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)); IActionResult result = this.CommentController.DeleteComment(id, null).Result; @@ -227,6 +238,7 @@ namespace DevHive.Web.Tests 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)); IActionResult result = this.CommentController.DeleteComment(id, null).Result; @@ -242,6 +254,7 @@ 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)); IActionResult result = this.CommentController.DeleteComment(Guid.Empty, null).Result; diff --git a/src/Web/DevHive.Web.Tests/PostController.Tests.cs b/src/Web/DevHive.Web.Tests/PostController.Tests.cs index f10f8dd..438eb80 100644 --- a/src/Web/DevHive.Web.Tests/PostController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/PostController.Tests.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Threading.Tasks; using AutoMapper; +using DevHive.Common.Jwt.Interfaces; using DevHive.Services.Interfaces; using DevHive.Services.Models.Post; using DevHive.Web.Controllers; @@ -18,6 +19,7 @@ namespace DevHive.Web.Tests const string MESSAGE = "Gosho Trapov"; private Mock PostServiceMock { get; set; } private Mock MapperMock { get; set; } + private Mock JwtServiceMock { get; set; } private PostController PostController { get; set; } [SetUp] @@ -25,7 +27,8 @@ namespace DevHive.Web.Tests { this.PostServiceMock = new Mock(); this.MapperMock = new Mock(); - this.PostController = new PostController(this.PostServiceMock.Object, this.MapperMock.Object); + this.JwtServiceMock = new Mock(); + this.PostController = new PostController(this.PostServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); } #region Create @@ -44,6 +47,7 @@ namespace DevHive.Web.Tests this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createPostServiceModel); this.PostServiceMock.Setup(p => p.CreatePost(It.IsAny())).Returns(Task.FromResult(id)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.PostServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); IActionResult result = this.PostController.Create(Guid.Empty, createPostWebModel, null).Result; @@ -77,6 +81,7 @@ namespace DevHive.Web.Tests this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); this.PostServiceMock.Setup(p => p.CreatePost(It.IsAny())).Returns(Task.FromResult(id)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.PostServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); IActionResult result = this.PostController.Create(Guid.Empty, createTechnologyWebModel, null).Result; @@ -150,6 +155,7 @@ namespace DevHive.Web.Tests this.PostServiceMock.Setup(p => p.UpdatePost(It.IsAny())).Returns(Task.FromResult(id)); this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updatePostServiceModel); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); IActionResult result = this.PostController.Update(id, updatePostWebModel, null).Result; @@ -173,6 +179,7 @@ namespace DevHive.Web.Tests this.PostServiceMock.Setup(p => p.UpdatePost(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updatePostServiceModel); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); IActionResult result = this.PostController.Update(id, updatePostWebModel, null).Result; @@ -207,6 +214,7 @@ namespace DevHive.Web.Tests Guid id = Guid.NewGuid(); this.PostServiceMock.Setup(p => p.DeletePost(It.IsAny())).Returns(Task.FromResult(true)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); IActionResult result = this.PostController.Delete(id, null).Result; @@ -221,6 +229,7 @@ namespace DevHive.Web.Tests Guid id = Guid.NewGuid(); this.PostServiceMock.Setup(p => p.DeletePost(It.IsAny())).Returns(Task.FromResult(false)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); IActionResult result = this.PostController.Delete(id, null).Result; diff --git a/src/Web/DevHive.Web.Tests/UserController.Tests.cs b/src/Web/DevHive.Web.Tests/UserController.Tests.cs index e12738e..ee08d88 100644 --- a/src/Web/DevHive.Web.Tests/UserController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/UserController.Tests.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using AutoMapper; +using DevHive.Common.Jwt.Interfaces; using DevHive.Common.Models.Identity; using DevHive.Services.Interfaces; using DevHive.Services.Models.User; @@ -18,6 +19,7 @@ namespace DevHive.Web.Tests const string USERNAME = "Gosho Trapov"; private Mock UserServiceMock { get; set; } private Mock MapperMock { get; set; } + private Mock JwtServiceMock { get; set; } private UserController UserController { get; set; } [SetUp] @@ -25,7 +27,8 @@ namespace DevHive.Web.Tests { this.UserServiceMock = new Mock(); this.MapperMock = new Mock(); - this.UserController = new UserController(this.UserServiceMock.Object, this.MapperMock.Object); + this.JwtServiceMock = new Mock(); + this.UserController = new UserController(this.UserServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); } #region Create @@ -103,7 +106,7 @@ namespace DevHive.Web.Tests }; this.UserServiceMock.Setup(p => p.GetUserById(It.IsAny())).Returns(Task.FromResult(userServiceModel)); - this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(userWebModel); IActionResult result = this.UserController.GetById(id, null).Result; @@ -119,7 +122,7 @@ namespace DevHive.Web.Tests [Test] public void GetById_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(false); IActionResult result = this.UserController.GetById(Guid.NewGuid(), null).Result; @@ -171,44 +174,13 @@ namespace DevHive.Web.Tests }; this.UserServiceMock.Setup(p => p.UpdateUser(It.IsAny())).Returns(Task.FromResult(userServiceModel)); - this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateUserServiceModel); IActionResult result = this.UserController.Update(id, updateUserWebModel, null).Result; Assert.IsInstanceOf(result); } - - [Test] - public void UpdateProfilePicture_ShouldReturnOkObjectResult_WhenProfilePictureIsUpdatedSuccessfully() - { - string profilePictureURL = "goshotrapov"; - UpdateProfilePictureWebModel updateProfilePictureWebModel = new(); - UpdateProfilePictureServiceModel updateProfilePictureServiceModel = new(); - ProfilePictureServiceModel profilePictureServiceModel = new() - { - ProfilePictureURL = profilePictureURL - }; - ProfilePictureWebModel profilePictureWebModel = new() - { - ProfilePictureURL = profilePictureURL - }; - - this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateProfilePictureServiceModel); - this.UserServiceMock.Setup(p => p.UpdateProfilePicture(It.IsAny())).Returns(Task.FromResult(profilePictureServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(profilePictureWebModel); - - - IActionResult result = this.UserController.UpdateProfilePicture(Guid.Empty, updateProfilePictureWebModel, null).Result; - - Assert.IsInstanceOf(result); - - AcceptedResult acceptedResult = result as AcceptedResult; - ProfilePictureWebModel resultModel = acceptedResult.Value as ProfilePictureWebModel; - - Assert.AreEqual(profilePictureURL, resultModel.ProfilePictureURL); - } #endregion #region Delete @@ -217,7 +189,7 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.UserServiceMock.Setup(p => p.DeleteUser(It.IsAny())).Returns(Task.FromResult(true)); IActionResult result = this.UserController.Delete(id, null).Result; @@ -231,7 +203,7 @@ namespace DevHive.Web.Tests string message = "Could not delete User"; Guid id = Guid.NewGuid(); - this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); this.UserServiceMock.Setup(p => p.DeleteUser(It.IsAny())).Returns(Task.FromResult(false)); IActionResult result = this.UserController.Delete(id, null).Result; -- cgit v1.2.3 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 +++++++++++----------- src/Web/DevHive.Web.Tests/FeedController.Tests.cs | 28 +++---- .../DevHive.Web.Tests/LanguageController.Tests.cs | 50 +++++------ src/Web/DevHive.Web.Tests/PostController.Tests.cs | 90 ++++++++++---------- src/Web/DevHive.Web.Tests/RoleController.Tests.cs | 50 +++++------ .../TechnologyController.Tests.cs | 51 ++++++------ src/Web/DevHive.Web.Tests/UserController.Tests.cs | 70 ++++++++-------- 7 files changed, 217 insertions(+), 218 deletions(-) (limited to 'src/Web') 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); } diff --git a/src/Web/DevHive.Web.Tests/FeedController.Tests.cs b/src/Web/DevHive.Web.Tests/FeedController.Tests.cs index 01f67e5..80a2a14 100644 --- a/src/Web/DevHive.Web.Tests/FeedController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/FeedController.Tests.cs @@ -17,17 +17,17 @@ namespace DevHive.Web.Tests [TestFixture] public class FeedControllerTests { - private Mock FeedServiceMock { get; set; } - private Mock MapperMock { get; set; } - private FeedController FeedController { get; set; } + private Mock _feedServiceMock; + private Mock _mapperMock; + private FeedController _feedController; #region SetUp [SetUp] public void SetUp() { - this.FeedServiceMock = new Mock(); - this.MapperMock = new Mock(); - this.FeedController = new FeedController(this.FeedServiceMock.Object, this.MapperMock.Object); + this._feedServiceMock = new Mock(); + this._mapperMock = new Mock(); + this._feedController = new FeedController(this._feedServiceMock.Object, this._mapperMock.Object); } #endregion @@ -48,11 +48,11 @@ namespace DevHive.Web.Tests } }; - this.FeedServiceMock.Setup(p => p.GetPage(It.IsAny())).Returns(Task.FromResult(readPageServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(getPageServiceModel); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPageWebModel); + this._feedServiceMock.Setup(p => p.GetPage(It.IsAny())).Returns(Task.FromResult(readPageServiceModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(getPageServiceModel); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPageWebModel); - IActionResult result = await this.FeedController.GetPosts(Guid.Empty, getPageWebModel); + IActionResult result = await this._feedController.GetPosts(Guid.Empty, getPageWebModel); Assert.IsInstanceOf(result); @@ -80,11 +80,11 @@ namespace DevHive.Web.Tests } }; - this.FeedServiceMock.Setup(p => p.GetUserPage(It.IsAny())).Returns(Task.FromResult(readPageServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(getPageServiceModel); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPageWebModel); + this._feedServiceMock.Setup(p => p.GetUserPage(It.IsAny())).Returns(Task.FromResult(readPageServiceModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(getPageServiceModel); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPageWebModel); - IActionResult result = await this.FeedController.GetUserPosts(null, getPageWebModel); + IActionResult result = await this._feedController.GetUserPosts(null, getPageWebModel); Assert.IsInstanceOf(result); diff --git a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs index af4672a..f11e1a1 100644 --- a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs @@ -16,16 +16,16 @@ namespace DevHive.Web.Tests public class LanguageControllerTests { const string NAME = "Gosho Trapov"; - private Mock LanguageServiceMock { get; set; } - private Mock MapperMock { get; set; } - private LanguageController LanguageController { get; set; } + private Mock _languageServiceMock; + private Mock _mapperMock; + private LanguageController _languageController; [SetUp] public void SetUp() { - this.LanguageServiceMock = new Mock(); - this.MapperMock = new Mock(); - this.LanguageController = new LanguageController(this.LanguageServiceMock.Object, this.MapperMock.Object); + this._languageServiceMock = new Mock(); + this._mapperMock = new Mock(); + this._languageController = new LanguageController(this._languageServiceMock.Object, this._mapperMock.Object); } #region Create @@ -42,10 +42,10 @@ namespace DevHive.Web.Tests }; Guid id = Guid.NewGuid(); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createLanguageServiceModel); - this.LanguageServiceMock.Setup(p => p.CreateLanguage(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createLanguageServiceModel); + this._languageServiceMock.Setup(p => p.CreateLanguage(It.IsAny())).Returns(Task.FromResult(id)); - IActionResult result = this.LanguageController.Create(createLanguageWebModel).Result; + IActionResult result = this._languageController.Create(createLanguageWebModel).Result; Assert.IsInstanceOf(result); @@ -74,10 +74,10 @@ namespace DevHive.Web.Tests Guid id = Guid.Empty; string errorMessage = $"Could not create language {NAME}"; - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this.LanguageServiceMock.Setup(p => p.CreateLanguage(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); + this._languageServiceMock.Setup(p => p.CreateLanguage(It.IsAny())).Returns(Task.FromResult(id)); - IActionResult result = this.LanguageController.Create(createTechnologyWebModel).Result; + IActionResult result = this._languageController.Create(createTechnologyWebModel).Result; Assert.IsInstanceOf(result); @@ -103,10 +103,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.LanguageServiceMock.Setup(p => p.GetLanguageById(It.IsAny())).Returns(Task.FromResult(readLanguageServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readLanguageWebModel); + this._languageServiceMock.Setup(p => p.GetLanguageById(It.IsAny())).Returns(Task.FromResult(readLanguageServiceModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readLanguageWebModel); - IActionResult result = this.LanguageController.GetById(id).Result; + IActionResult result = this._languageController.GetById(id).Result; Assert.IsInstanceOf(result); @@ -131,10 +131,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.LanguageServiceMock.Setup(p => p.UpdateLanguage(It.IsAny())).Returns(Task.FromResult(true)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateLanguageServiceModel); + this._languageServiceMock.Setup(p => p.UpdateLanguage(It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateLanguageServiceModel); - IActionResult result = this.LanguageController.Update(id, updateLanguageWebModel).Result; + IActionResult result = this._languageController.Update(id, updateLanguageWebModel).Result; Assert.IsInstanceOf(result); } @@ -153,10 +153,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.LanguageServiceMock.Setup(p => p.UpdateLanguage(It.IsAny())).Returns(Task.FromResult(false)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateLanguageServiceModel); + this._languageServiceMock.Setup(p => p.UpdateLanguage(It.IsAny())).Returns(Task.FromResult(false)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateLanguageServiceModel); - IActionResult result = this.LanguageController.Update(id, updateLanguageWebModel).Result; + IActionResult result = this._languageController.Update(id, updateLanguageWebModel).Result; Assert.IsInstanceOf(result); BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; @@ -172,9 +172,9 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.LanguageServiceMock.Setup(p => p.DeleteLanguage(It.IsAny())).Returns(Task.FromResult(true)); + this._languageServiceMock.Setup(p => p.DeleteLanguage(It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.LanguageController.Delete(id).Result; + IActionResult result = this._languageController.Delete(id).Result; Assert.IsInstanceOf(result); } @@ -185,9 +185,9 @@ namespace DevHive.Web.Tests string message = "Could not delete Language"; Guid id = Guid.NewGuid(); - this.LanguageServiceMock.Setup(p => p.DeleteLanguage(It.IsAny())).Returns(Task.FromResult(false)); + this._languageServiceMock.Setup(p => p.DeleteLanguage(It.IsAny())).Returns(Task.FromResult(false)); - IActionResult result = this.LanguageController.Delete(id).Result; + IActionResult result = this._languageController.Delete(id).Result; Assert.IsInstanceOf(result); 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 PostServiceMock { get; set; } - private Mock MapperMock { get; set; } - private Mock JwtServiceMock { get; set; } - private PostController PostController { get; set; } + private Mock _postServiceMock; + private Mock _mapperMock; + private Mock _jwtServiceMock; + private PostController _postController; [SetUp] public void SetUp() { - this.PostServiceMock = new Mock(); - this.MapperMock = new Mock(); - this.JwtServiceMock = new Mock(); - this.PostController = new PostController(this.PostServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); + this._postServiceMock = new Mock(); + this._mapperMock = new Mock(); + this._jwtServiceMock = new Mock(); + 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(It.IsAny())).Returns(createPostServiceModel); - this.PostServiceMock.Setup(p => p.CreatePost(It.IsAny())).Returns(Task.FromResult(id)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createPostServiceModel); + this._postServiceMock.Setup(p => p.CreatePost(It.IsAny())).Returns(Task.FromResult(id)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).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(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(It.IsAny())).Returns(createTechnologyServiceModel); - this.PostServiceMock.Setup(p => p.CreatePost(It.IsAny())).Returns(Task.FromResult(id)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); + this._postServiceMock.Setup(p => p.CreatePost(It.IsAny())).Returns(Task.FromResult(id)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).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(result); @@ -102,9 +102,9 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this.PostServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).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(result); } @@ -125,10 +125,10 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this.PostServiceMock.Setup(p => p.GetPostById(It.IsAny())).Returns(Task.FromResult(readPostServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPostWebModel); + this._postServiceMock.Setup(p => p.GetPostById(It.IsAny())).Returns(Task.FromResult(readPostServiceModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPostWebModel); - IActionResult result = this.PostController.GetById(id).Result; + IActionResult result = this._postController.GetById(id).Result; Assert.IsInstanceOf(result); @@ -153,12 +153,12 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.PostServiceMock.Setup(p => p.UpdatePost(It.IsAny())).Returns(Task.FromResult(id)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updatePostServiceModel); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._postServiceMock.Setup(p => p.UpdatePost(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updatePostServiceModel); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Update(id, updatePostWebModel, null).Result; + IActionResult result = this._postController.Update(id, updatePostWebModel, null).Result; Assert.IsInstanceOf(result); } @@ -177,12 +177,12 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.PostServiceMock.Setup(p => p.UpdatePost(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updatePostServiceModel); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._postServiceMock.Setup(p => p.UpdatePost(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updatePostServiceModel); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Update(id, updatePostWebModel, null).Result; + IActionResult result = this._postController.Update(id, updatePostWebModel, null).Result; Assert.IsInstanceOf(result); BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; @@ -199,9 +199,9 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).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(result); } @@ -213,11 +213,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.PostServiceMock.Setup(p => p.DeletePost(It.IsAny())).Returns(Task.FromResult(true)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._postServiceMock.Setup(p => p.DeletePost(It.IsAny())).Returns(Task.FromResult(true)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Delete(id, null).Result; + IActionResult result = this._postController.Delete(id, null).Result; Assert.IsInstanceOf(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())).Returns(Task.FromResult(false)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._postServiceMock.Setup(p => p.DeletePost(It.IsAny())).Returns(Task.FromResult(false)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.PostController.Delete(id, null).Result; + IActionResult result = this._postController.Delete(id, null).Result; Assert.IsInstanceOf(result); @@ -245,9 +245,9 @@ namespace DevHive.Web.Tests [Test] public void DeletePost_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - this.PostServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - IActionResult result = this.PostController.Delete(Guid.Empty, null).Result; + IActionResult result = this._postController.Delete(Guid.Empty, null).Result; Assert.IsInstanceOf(result); } diff --git a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs index ff80dc0..83358a0 100644 --- a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs @@ -16,16 +16,16 @@ namespace DevHive.Web.Tests public class RoleControllerTests { const string NAME = "Gosho Trapov"; - private Mock RoleServiceMock { get; set; } - private Mock MapperMock { get; set; } - private RoleController RoleController { get; set; } + private Mock _roleServiceMock; + private Mock _mapperMock; + private RoleController _roleController; [SetUp] public void SetUp() { - this.RoleServiceMock = new Mock(); - this.MapperMock = new Mock(); - this.RoleController = new RoleController(this.RoleServiceMock.Object, this.MapperMock.Object); + this._roleServiceMock = new Mock(); + this._mapperMock = new Mock(); + this._roleController = new RoleController(this._roleServiceMock.Object, this._mapperMock.Object); } #region Create @@ -42,10 +42,10 @@ namespace DevHive.Web.Tests }; Guid id = Guid.NewGuid(); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createRoleServiceModel); - this.RoleServiceMock.Setup(p => p.CreateRole(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createRoleServiceModel); + this._roleServiceMock.Setup(p => p.CreateRole(It.IsAny())).Returns(Task.FromResult(id)); - IActionResult result = this.RoleController.Create(createRoleWebModel).Result; + IActionResult result = this._roleController.Create(createRoleWebModel).Result; Assert.IsInstanceOf(result); @@ -74,10 +74,10 @@ namespace DevHive.Web.Tests Guid id = Guid.Empty; string errorMessage = $"Could not create role {NAME}"; - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this.RoleServiceMock.Setup(p => p.CreateRole(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); + this._roleServiceMock.Setup(p => p.CreateRole(It.IsAny())).Returns(Task.FromResult(id)); - IActionResult result = this.RoleController.Create(createTechnologyWebModel).Result; + IActionResult result = this._roleController.Create(createTechnologyWebModel).Result; Assert.IsInstanceOf(result); @@ -103,10 +103,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.RoleServiceMock.Setup(p => p.GetRoleById(It.IsAny())).Returns(Task.FromResult(roleServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(roleWebModel); + this._roleServiceMock.Setup(p => p.GetRoleById(It.IsAny())).Returns(Task.FromResult(roleServiceModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(roleWebModel); - IActionResult result = this.RoleController.GetById(id).Result; + IActionResult result = this._roleController.GetById(id).Result; Assert.IsInstanceOf(result); @@ -131,10 +131,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.RoleServiceMock.Setup(p => p.UpdateRole(It.IsAny())).Returns(Task.FromResult(true)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRoleServiceModel); + this._roleServiceMock.Setup(p => p.UpdateRole(It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRoleServiceModel); - IActionResult result = this.RoleController.Update(id, updateRoleWebModel).Result; + IActionResult result = this._roleController.Update(id, updateRoleWebModel).Result; Assert.IsInstanceOf(result); } @@ -153,10 +153,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.RoleServiceMock.Setup(p => p.UpdateRole(It.IsAny())).Returns(Task.FromResult(false)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRoleServiceModel); + this._roleServiceMock.Setup(p => p.UpdateRole(It.IsAny())).Returns(Task.FromResult(false)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRoleServiceModel); - IActionResult result = this.RoleController.Update(id, updateRoleWebModel).Result; + IActionResult result = this._roleController.Update(id, updateRoleWebModel).Result; Assert.IsInstanceOf(result); BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; @@ -172,9 +172,9 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.RoleServiceMock.Setup(p => p.DeleteRole(It.IsAny())).Returns(Task.FromResult(true)); + this._roleServiceMock.Setup(p => p.DeleteRole(It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.RoleController.Delete(id).Result; + IActionResult result = this._roleController.Delete(id).Result; Assert.IsInstanceOf(result); } @@ -185,9 +185,9 @@ namespace DevHive.Web.Tests string message = "Could not delete role!"; Guid id = Guid.NewGuid(); - this.RoleServiceMock.Setup(p => p.DeleteRole(It.IsAny())).Returns(Task.FromResult(false)); + this._roleServiceMock.Setup(p => p.DeleteRole(It.IsAny())).Returns(Task.FromResult(false)); - IActionResult result = this.RoleController.Delete(id).Result; + IActionResult result = this._roleController.Delete(id).Result; Assert.IsInstanceOf(result); diff --git a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs index a00f1db..64b128c 100644 --- a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs @@ -1,5 +1,4 @@ using AutoMapper; -using DevHive.Common.Models.Misc; using DevHive.Services.Interfaces; using DevHive.Services.Models.Technology; using DevHive.Web.Controllers; @@ -17,17 +16,17 @@ namespace DevHive.Web.Tests public class TechnologyControllerTests { const string NAME = "Gosho Trapov"; - private Mock TechnologyServiceMock { get; set; } - private Mock MapperMock { get; set; } - private TechnologyController TechnologyController { get; set; } + private Mock _technologyServiceMock; + private Mock _mapperMock; + private TechnologyController _technologyController; #region SetUp [SetUp] public void SetUp() { - this.TechnologyServiceMock = new Mock(); - this.MapperMock = new Mock(); - this.TechnologyController = new TechnologyController(this.TechnologyServiceMock.Object, this.MapperMock.Object); + this._technologyServiceMock = new Mock(); + this._mapperMock = new Mock(); + this._technologyController = new TechnologyController(this._technologyServiceMock.Object, this._mapperMock.Object); } #endregion @@ -45,10 +44,10 @@ namespace DevHive.Web.Tests }; Guid id = Guid.NewGuid(); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this.TechnologyServiceMock.Setup(p => p.CreateTechnology(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); + this._technologyServiceMock.Setup(p => p.CreateTechnology(It.IsAny())).Returns(Task.FromResult(id)); - IActionResult result = this.TechnologyController.Create(createTechnologyWebModel).Result; + IActionResult result = this._technologyController.Create(createTechnologyWebModel).Result; Assert.IsInstanceOf(result); @@ -77,10 +76,10 @@ namespace DevHive.Web.Tests Guid id = Guid.Empty; string errorMessage = $"Could not create technology {NAME}"; - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this.TechnologyServiceMock.Setup(p => p.CreateTechnology(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); + this._technologyServiceMock.Setup(p => p.CreateTechnology(It.IsAny())).Returns(Task.FromResult(id)); - IActionResult result = this.TechnologyController.Create(createTechnologyWebModel).Result; + IActionResult result = this._technologyController.Create(createTechnologyWebModel).Result; Assert.IsInstanceOf(result); @@ -106,10 +105,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.TechnologyServiceMock.Setup(p => p.GetTechnologyById(It.IsAny())).Returns(Task.FromResult(readTechnologyServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readTechnologyWebModel); + this._technologyServiceMock.Setup(p => p.GetTechnologyById(It.IsAny())).Returns(Task.FromResult(readTechnologyServiceModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readTechnologyWebModel); - IActionResult result = this.TechnologyController.GetById(id).Result; + IActionResult result = this._technologyController.GetById(id).Result; Assert.IsInstanceOf(result); @@ -134,10 +133,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.TechnologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny())).Returns(Task.FromResult(true)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateTechnologyServiceModel); + this._technologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateTechnologyServiceModel); - IActionResult result = this.TechnologyController.Update(id, updateTechnologyWebModel).Result; + IActionResult result = this._technologyController.Update(id, updateTechnologyWebModel).Result; Assert.IsInstanceOf(result); } @@ -156,10 +155,10 @@ namespace DevHive.Web.Tests Name = NAME }; - this.TechnologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny())).Returns(Task.FromResult(false)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateTechnologyServiceModel); + this._technologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny())).Returns(Task.FromResult(false)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateTechnologyServiceModel); - IActionResult result = this.TechnologyController.Update(id, updateTechnologyWebModel).Result; + IActionResult result = this._technologyController.Update(id, updateTechnologyWebModel).Result; Assert.IsInstanceOf(result); BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; @@ -175,9 +174,9 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.TechnologyServiceMock.Setup(p => p.DeleteTechnology(It.IsAny())).Returns(Task.FromResult(true)); + this._technologyServiceMock.Setup(p => p.DeleteTechnology(It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.TechnologyController.Delete(id).Result; + IActionResult result = this._technologyController.Delete(id).Result; Assert.IsInstanceOf(result); } @@ -188,9 +187,9 @@ namespace DevHive.Web.Tests string message = "Could not delete Technology"; Guid id = Guid.NewGuid(); - this.TechnologyServiceMock.Setup(p => p.DeleteTechnology(It.IsAny())).Returns(Task.FromResult(false)); + this._technologyServiceMock.Setup(p => p.DeleteTechnology(It.IsAny())).Returns(Task.FromResult(false)); - IActionResult result = this.TechnologyController.Delete(id).Result; + IActionResult result = this._technologyController.Delete(id).Result; Assert.IsInstanceOf(result); diff --git a/src/Web/DevHive.Web.Tests/UserController.Tests.cs b/src/Web/DevHive.Web.Tests/UserController.Tests.cs index ee08d88..89e5fc9 100644 --- a/src/Web/DevHive.Web.Tests/UserController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/UserController.Tests.cs @@ -17,18 +17,18 @@ namespace DevHive.Web.Tests public class UserControllerTests { const string USERNAME = "Gosho Trapov"; - private Mock UserServiceMock { get; set; } - private Mock MapperMock { get; set; } - private Mock JwtServiceMock { get; set; } - private UserController UserController { get; set; } + private Mock _userServiceMock; + private Mock _mapperMock; + private Mock _jwtServiceMock; + private UserController _userController; [SetUp] public void SetUp() { - this.UserServiceMock = new Mock(); - this.MapperMock = new Mock(); - this.JwtServiceMock = new Mock(); - this.UserController = new UserController(this.UserServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); + this._userServiceMock = new Mock(); + this._mapperMock = new Mock(); + this._jwtServiceMock = new Mock(); + this._userController = new UserController(this._userServiceMock.Object, this._mapperMock.Object, this._jwtServiceMock.Object); } #region Create @@ -47,11 +47,11 @@ namespace DevHive.Web.Tests TokenModel tokenModel = new(token); TokenWebModel tokenWebModel = new(token); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(loginServiceModel); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(tokenWebModel); - this.UserServiceMock.Setup(p => p.LoginUser(It.IsAny())).Returns(Task.FromResult(tokenModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(loginServiceModel); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(tokenWebModel); + this._userServiceMock.Setup(p => p.LoginUser(It.IsAny())).Returns(Task.FromResult(tokenModel)); - IActionResult result = this.UserController.Login(loginWebModel).Result; + IActionResult result = this._userController.Login(loginWebModel).Result; Assert.IsInstanceOf(result); @@ -75,11 +75,11 @@ namespace DevHive.Web.Tests TokenModel tokenModel = new(token); TokenWebModel tokenWebModel = new(token); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(registerServiceModel); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(tokenWebModel); - this.UserServiceMock.Setup(p => p.RegisterUser(It.IsAny())).Returns(Task.FromResult(tokenModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(registerServiceModel); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(tokenWebModel); + this._userServiceMock.Setup(p => p.RegisterUser(It.IsAny())).Returns(Task.FromResult(tokenModel)); - IActionResult result = this.UserController.Register(registerWebModel).Result; + IActionResult result = this._userController.Register(registerWebModel).Result; Assert.IsInstanceOf(result); @@ -105,11 +105,11 @@ namespace DevHive.Web.Tests UserName = USERNAME }; - this.UserServiceMock.Setup(p => p.GetUserById(It.IsAny())).Returns(Task.FromResult(userServiceModel)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(userWebModel); + this._userServiceMock.Setup(p => p.GetUserById(It.IsAny())).Returns(Task.FromResult(userServiceModel)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(userWebModel); - IActionResult result = this.UserController.GetById(id, null).Result; + IActionResult result = this._userController.GetById(id, null).Result; Assert.IsInstanceOf(result); @@ -122,9 +122,9 @@ namespace DevHive.Web.Tests [Test] public void GetById_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(false); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(false); - IActionResult result = this.UserController.GetById(Guid.NewGuid(), null).Result; + IActionResult result = this._userController.GetById(Guid.NewGuid(), null).Result; Assert.IsInstanceOf(result); } @@ -141,10 +141,10 @@ namespace DevHive.Web.Tests UserName = USERNAME }; - this.UserServiceMock.Setup(p => p.GetUserByUsername(It.IsAny())).Returns(Task.FromResult(userServiceModel)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(userWebModel); + this._userServiceMock.Setup(p => p.GetUserByUsername(It.IsAny())).Returns(Task.FromResult(userServiceModel)); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(userWebModel); - IActionResult result = this.UserController.GetUser(null).Result; + IActionResult result = this._userController.GetUser(null).Result; Assert.IsInstanceOf(result); @@ -173,11 +173,11 @@ namespace DevHive.Web.Tests UserName = USERNAME }; - this.UserServiceMock.Setup(p => p.UpdateUser(It.IsAny())).Returns(Task.FromResult(userServiceModel)); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateUserServiceModel); + this._userServiceMock.Setup(p => p.UpdateUser(It.IsAny())).Returns(Task.FromResult(userServiceModel)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateUserServiceModel); - IActionResult result = this.UserController.Update(id, updateUserWebModel, null).Result; + IActionResult result = this._userController.Update(id, updateUserWebModel, null).Result; Assert.IsInstanceOf(result); } @@ -189,10 +189,10 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.UserServiceMock.Setup(p => p.DeleteUser(It.IsAny())).Returns(Task.FromResult(true)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._userServiceMock.Setup(p => p.DeleteUser(It.IsAny())).Returns(Task.FromResult(true)); - IActionResult result = this.UserController.Delete(id, null).Result; + IActionResult result = this._userController.Delete(id, null).Result; Assert.IsInstanceOf(result); } @@ -203,10 +203,10 @@ namespace DevHive.Web.Tests string message = "Could not delete User"; Guid id = Guid.NewGuid(); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.UserServiceMock.Setup(p => p.DeleteUser(It.IsAny())).Returns(Task.FromResult(false)); + this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); + this._userServiceMock.Setup(p => p.DeleteUser(It.IsAny())).Returns(Task.FromResult(false)); - IActionResult result = this.UserController.Delete(id, null).Result; + IActionResult result = this._userController.Delete(id, null).Result; Assert.IsInstanceOf(result); -- cgit v1.2.3 From a2dde73b37ad311213a6787fb5aeb5cb4103968c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 11:23:35 +0200 Subject: Updated code style of mock setups in Web layer tests --- .../DevHive.Web.Tests/CommentController.Tests.cs | 120 +++++++++++++++------ src/Web/DevHive.Web.Tests/FeedController.Tests.cs | 24 +++-- .../DevHive.Web.Tests/LanguageController.Tests.cs | 48 ++++++--- src/Web/DevHive.Web.Tests/PostController.Tests.cs | 108 ++++++++++++++----- src/Web/DevHive.Web.Tests/RoleController.Tests.cs | 50 ++++++--- .../TechnologyController.Tests.cs | 48 ++++++--- src/Web/DevHive.Web.Tests/UserController.Tests.cs | 76 +++++++++---- 7 files changed, 355 insertions(+), 119 deletions(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs index 3b7f0a9..4e1715c 100644 --- a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs @@ -47,10 +47,18 @@ 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; @@ -81,10 +89,18 @@ 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; @@ -104,8 +120,12 @@ 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; @@ -127,9 +147,15 @@ 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; @@ -156,10 +182,18 @@ 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; @@ -185,10 +219,18 @@ 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; Assert.IsInstanceOf(result); @@ -207,7 +249,9 @@ 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; @@ -222,9 +266,15 @@ 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; @@ -237,9 +287,15 @@ 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; @@ -254,8 +310,12 @@ 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; diff --git a/src/Web/DevHive.Web.Tests/FeedController.Tests.cs b/src/Web/DevHive.Web.Tests/FeedController.Tests.cs index 80a2a14..7a7fd8d 100644 --- a/src/Web/DevHive.Web.Tests/FeedController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/FeedController.Tests.cs @@ -48,9 +48,15 @@ namespace DevHive.Web.Tests } }; - this._feedServiceMock.Setup(p => p.GetPage(It.IsAny())).Returns(Task.FromResult(readPageServiceModel)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(getPageServiceModel); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPageWebModel); + this._feedServiceMock + .Setup(p => p.GetPage(It.IsAny())) + .Returns(Task.FromResult(readPageServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(getPageServiceModel); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readPageWebModel); IActionResult result = await this._feedController.GetPosts(Guid.Empty, getPageWebModel); @@ -80,9 +86,15 @@ namespace DevHive.Web.Tests } }; - this._feedServiceMock.Setup(p => p.GetUserPage(It.IsAny())).Returns(Task.FromResult(readPageServiceModel)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(getPageServiceModel); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPageWebModel); + this._feedServiceMock + .Setup(p => p.GetUserPage(It.IsAny())) + .Returns(Task.FromResult(readPageServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(getPageServiceModel); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readPageWebModel); IActionResult result = await this._feedController.GetUserPosts(null, getPageWebModel); diff --git a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs index f11e1a1..de882fc 100644 --- a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs @@ -42,8 +42,12 @@ namespace DevHive.Web.Tests }; Guid id = Guid.NewGuid(); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createLanguageServiceModel); - this._languageServiceMock.Setup(p => p.CreateLanguage(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createLanguageServiceModel); + this._languageServiceMock + .Setup(p => p.CreateLanguage(It.IsAny())) + .Returns(Task.FromResult(id)); IActionResult result = this._languageController.Create(createLanguageWebModel).Result; @@ -74,8 +78,12 @@ namespace DevHive.Web.Tests Guid id = Guid.Empty; string errorMessage = $"Could not create language {NAME}"; - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this._languageServiceMock.Setup(p => p.CreateLanguage(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createTechnologyServiceModel); + this._languageServiceMock + .Setup(p => p.CreateLanguage(It.IsAny())) + .Returns(Task.FromResult(id)); IActionResult result = this._languageController.Create(createTechnologyWebModel).Result; @@ -103,8 +111,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._languageServiceMock.Setup(p => p.GetLanguageById(It.IsAny())).Returns(Task.FromResult(readLanguageServiceModel)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readLanguageWebModel); + this._languageServiceMock + .Setup(p => p.GetLanguageById(It.IsAny())) + .Returns(Task.FromResult(readLanguageServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readLanguageWebModel); IActionResult result = this._languageController.GetById(id).Result; @@ -131,8 +143,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._languageServiceMock.Setup(p => p.UpdateLanguage(It.IsAny())).Returns(Task.FromResult(true)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateLanguageServiceModel); + this._languageServiceMock + .Setup(p => p.UpdateLanguage(It.IsAny())) + .Returns(Task.FromResult(true)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateLanguageServiceModel); IActionResult result = this._languageController.Update(id, updateLanguageWebModel).Result; @@ -153,8 +169,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._languageServiceMock.Setup(p => p.UpdateLanguage(It.IsAny())).Returns(Task.FromResult(false)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateLanguageServiceModel); + this._languageServiceMock + .Setup(p => p.UpdateLanguage(It.IsAny())) + .Returns(Task.FromResult(false)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateLanguageServiceModel); IActionResult result = this._languageController.Update(id, updateLanguageWebModel).Result; Assert.IsInstanceOf(result); @@ -172,7 +192,9 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this._languageServiceMock.Setup(p => p.DeleteLanguage(It.IsAny())).Returns(Task.FromResult(true)); + this._languageServiceMock + .Setup(p => p.DeleteLanguage(It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._languageController.Delete(id).Result; @@ -185,7 +207,9 @@ namespace DevHive.Web.Tests string message = "Could not delete Language"; Guid id = Guid.NewGuid(); - this._languageServiceMock.Setup(p => p.DeleteLanguage(It.IsAny())).Returns(Task.FromResult(false)); + this._languageServiceMock + .Setup(p => p.DeleteLanguage(It.IsAny())) + .Returns(Task.FromResult(false)); IActionResult result = this._languageController.Delete(id).Result; diff --git a/src/Web/DevHive.Web.Tests/PostController.Tests.cs b/src/Web/DevHive.Web.Tests/PostController.Tests.cs index c2c2fbc..384a92a 100644 --- a/src/Web/DevHive.Web.Tests/PostController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/PostController.Tests.cs @@ -45,10 +45,18 @@ namespace DevHive.Web.Tests }; Guid id = Guid.NewGuid(); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createPostServiceModel); - this._postServiceMock.Setup(p => p.CreatePost(It.IsAny())).Returns(Task.FromResult(id)); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createPostServiceModel); + this._postServiceMock + .Setup(p => p.CreatePost(It.IsAny())) + .Returns(Task.FromResult(id)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._postServiceMock + .Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._postController.Create(Guid.Empty, createPostWebModel, null).Result; @@ -79,10 +87,18 @@ namespace DevHive.Web.Tests Guid id = Guid.Empty; string errorMessage = $"Could not create post!"; - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this._postServiceMock.Setup(p => p.CreatePost(It.IsAny())).Returns(Task.FromResult(id)); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createTechnologyServiceModel); + this._postServiceMock + .Setup(p => p.CreatePost(It.IsAny())) + .Returns(Task.FromResult(id)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._postServiceMock + .Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._postController.Create(Guid.Empty, createTechnologyWebModel, null).Result; @@ -102,7 +118,9 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this._postServiceMock.Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._postServiceMock + .Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); IActionResult result = this._postController.Create(Guid.NewGuid(), createPostWebModel, null).Result; @@ -125,8 +143,12 @@ namespace DevHive.Web.Tests Message = MESSAGE }; - this._postServiceMock.Setup(p => p.GetPostById(It.IsAny())).Returns(Task.FromResult(readPostServiceModel)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readPostWebModel); + this._postServiceMock + .Setup(p => p.GetPostById(It.IsAny())) + .Returns(Task.FromResult(readPostServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readPostWebModel); IActionResult result = this._postController.GetById(id).Result; @@ -153,10 +175,18 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this._postServiceMock.Setup(p => p.UpdatePost(It.IsAny())).Returns(Task.FromResult(id)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updatePostServiceModel); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._postServiceMock + .Setup(p => p.UpdatePost(It.IsAny())) + .Returns(Task.FromResult(id)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updatePostServiceModel); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._postServiceMock + .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._postController.Update(id, updatePostWebModel, null).Result; @@ -177,10 +207,18 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this._postServiceMock.Setup(p => p.UpdatePost(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updatePostServiceModel); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._postServiceMock + .Setup(p => p.UpdatePost(It.IsAny())) + .Returns(Task.FromResult(Guid.Empty)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updatePostServiceModel); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._postServiceMock + .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._postController.Update(id, updatePostWebModel, null).Result; Assert.IsInstanceOf(result); @@ -199,7 +237,9 @@ namespace DevHive.Web.Tests NewMessage = MESSAGE }; - this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._postServiceMock + .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); IActionResult result = this._postController.Update(Guid.Empty, updatePostWebModel, null).Result; @@ -213,9 +253,15 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this._postServiceMock.Setup(p => p.DeletePost(It.IsAny())).Returns(Task.FromResult(true)); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._postServiceMock + .Setup(p => p.DeletePost(It.IsAny())) + .Returns(Task.FromResult(true)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._postServiceMock + .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._postController.Delete(id, null).Result; @@ -228,9 +274,15 @@ namespace DevHive.Web.Tests string message = "Could not delete Post"; Guid id = Guid.NewGuid(); - this._postServiceMock.Setup(p => p.DeletePost(It.IsAny())).Returns(Task.FromResult(false)); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + this._postServiceMock + .Setup(p => p.DeletePost(It.IsAny())) + .Returns(Task.FromResult(false)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._postServiceMock + .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._postController.Delete(id, null).Result; @@ -245,7 +297,9 @@ namespace DevHive.Web.Tests [Test] public void DeletePost_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - this._postServiceMock.Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._postServiceMock + .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); IActionResult result = this._postController.Delete(Guid.Empty, null).Result; diff --git a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs index 83358a0..0f835c1 100644 --- a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs @@ -42,8 +42,12 @@ namespace DevHive.Web.Tests }; Guid id = Guid.NewGuid(); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createRoleServiceModel); - this._roleServiceMock.Setup(p => p.CreateRole(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createRoleServiceModel); + this._roleServiceMock + .Setup(p => p.CreateRole(It.IsAny())) + .Returns(Task.FromResult(id)); IActionResult result = this._roleController.Create(createRoleWebModel).Result; @@ -74,8 +78,12 @@ namespace DevHive.Web.Tests Guid id = Guid.Empty; string errorMessage = $"Could not create role {NAME}"; - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this._roleServiceMock.Setup(p => p.CreateRole(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createTechnologyServiceModel); + this._roleServiceMock + .Setup(p => p.CreateRole(It.IsAny())) + .Returns(Task.FromResult(id)); IActionResult result = this._roleController.Create(createTechnologyWebModel).Result; @@ -103,8 +111,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._roleServiceMock.Setup(p => p.GetRoleById(It.IsAny())).Returns(Task.FromResult(roleServiceModel)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(roleWebModel); + this._roleServiceMock + .Setup(p => p.GetRoleById(It.IsAny())) + .Returns(Task.FromResult(roleServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(roleWebModel); IActionResult result = this._roleController.GetById(id).Result; @@ -131,8 +143,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._roleServiceMock.Setup(p => p.UpdateRole(It.IsAny())).Returns(Task.FromResult(true)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRoleServiceModel); + this._roleServiceMock + .Setup(p => p.UpdateRole(It.IsAny())) + .Returns(Task.FromResult(true)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateRoleServiceModel); IActionResult result = this._roleController.Update(id, updateRoleWebModel).Result; @@ -153,8 +169,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._roleServiceMock.Setup(p => p.UpdateRole(It.IsAny())).Returns(Task.FromResult(false)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRoleServiceModel); + this._roleServiceMock + .Setup(p => p.UpdateRole(It.IsAny())) + .Returns(Task.FromResult(false)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateRoleServiceModel); IActionResult result = this._roleController.Update(id, updateRoleWebModel).Result; Assert.IsInstanceOf(result); @@ -172,7 +192,9 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this._roleServiceMock.Setup(p => p.DeleteRole(It.IsAny())).Returns(Task.FromResult(true)); + this._roleServiceMock + .Setup(p => p.DeleteRole(It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._roleController.Delete(id).Result; @@ -180,12 +202,14 @@ namespace DevHive.Web.Tests } [Test] - public void Delet_ReturnsBadRequestObjectResult_WhenRoleIsNotDeletedSuccessfully() + public void Delete_ReturnsBadRequestObjectResult_WhenRoleIsNotDeletedSuccessfully() { string message = "Could not delete role!"; Guid id = Guid.NewGuid(); - this._roleServiceMock.Setup(p => p.DeleteRole(It.IsAny())).Returns(Task.FromResult(false)); + this._roleServiceMock + .Setup(p => p.DeleteRole(It.IsAny())) + .Returns(Task.FromResult(false)); IActionResult result = this._roleController.Delete(id).Result; diff --git a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs index 64b128c..76d291d 100644 --- a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs @@ -44,8 +44,12 @@ namespace DevHive.Web.Tests }; Guid id = Guid.NewGuid(); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this._technologyServiceMock.Setup(p => p.CreateTechnology(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createTechnologyServiceModel); + this._technologyServiceMock + .Setup(p => p.CreateTechnology(It.IsAny())) + .Returns(Task.FromResult(id)); IActionResult result = this._technologyController.Create(createTechnologyWebModel).Result; @@ -76,8 +80,12 @@ namespace DevHive.Web.Tests Guid id = Guid.Empty; string errorMessage = $"Could not create technology {NAME}"; - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); - this._technologyServiceMock.Setup(p => p.CreateTechnology(It.IsAny())).Returns(Task.FromResult(id)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createTechnologyServiceModel); + this._technologyServiceMock + .Setup(p => p.CreateTechnology(It.IsAny())) + .Returns(Task.FromResult(id)); IActionResult result = this._technologyController.Create(createTechnologyWebModel).Result; @@ -105,8 +113,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._technologyServiceMock.Setup(p => p.GetTechnologyById(It.IsAny())).Returns(Task.FromResult(readTechnologyServiceModel)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readTechnologyWebModel); + this._technologyServiceMock + .Setup(p => p.GetTechnologyById(It.IsAny())) + .Returns(Task.FromResult(readTechnologyServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readTechnologyWebModel); IActionResult result = this._technologyController.GetById(id).Result; @@ -133,8 +145,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._technologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny())).Returns(Task.FromResult(true)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateTechnologyServiceModel); + this._technologyServiceMock + .Setup(p => p.UpdateTechnology(It.IsAny())) + .Returns(Task.FromResult(true)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateTechnologyServiceModel); IActionResult result = this._technologyController.Update(id, updateTechnologyWebModel).Result; @@ -155,8 +171,12 @@ namespace DevHive.Web.Tests Name = NAME }; - this._technologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny())).Returns(Task.FromResult(false)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateTechnologyServiceModel); + this._technologyServiceMock + .Setup(p => p.UpdateTechnology(It.IsAny())) + .Returns(Task.FromResult(false)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateTechnologyServiceModel); IActionResult result = this._technologyController.Update(id, updateTechnologyWebModel).Result; Assert.IsInstanceOf(result); @@ -174,7 +194,9 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this._technologyServiceMock.Setup(p => p.DeleteTechnology(It.IsAny())).Returns(Task.FromResult(true)); + this._technologyServiceMock + .Setup(p => p.DeleteTechnology(It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._technologyController.Delete(id).Result; @@ -187,7 +209,9 @@ namespace DevHive.Web.Tests string message = "Could not delete Technology"; Guid id = Guid.NewGuid(); - this._technologyServiceMock.Setup(p => p.DeleteTechnology(It.IsAny())).Returns(Task.FromResult(false)); + this._technologyServiceMock + .Setup(p => p.DeleteTechnology(It.IsAny())) + .Returns(Task.FromResult(false)); IActionResult result = this._technologyController.Delete(id).Result; diff --git a/src/Web/DevHive.Web.Tests/UserController.Tests.cs b/src/Web/DevHive.Web.Tests/UserController.Tests.cs index 89e5fc9..ad7bdd9 100644 --- a/src/Web/DevHive.Web.Tests/UserController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/UserController.Tests.cs @@ -47,9 +47,15 @@ namespace DevHive.Web.Tests TokenModel tokenModel = new(token); TokenWebModel tokenWebModel = new(token); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(loginServiceModel); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(tokenWebModel); - this._userServiceMock.Setup(p => p.LoginUser(It.IsAny())).Returns(Task.FromResult(tokenModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(loginServiceModel); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(tokenWebModel); + this._userServiceMock + .Setup(p => p.LoginUser(It.IsAny())) + .Returns(Task.FromResult(tokenModel)); IActionResult result = this._userController.Login(loginWebModel).Result; @@ -75,9 +81,15 @@ namespace DevHive.Web.Tests TokenModel tokenModel = new(token); TokenWebModel tokenWebModel = new(token); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(registerServiceModel); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(tokenWebModel); - this._userServiceMock.Setup(p => p.RegisterUser(It.IsAny())).Returns(Task.FromResult(tokenModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(registerServiceModel); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(tokenWebModel); + this._userServiceMock + .Setup(p => p.RegisterUser(It.IsAny())) + .Returns(Task.FromResult(tokenModel)); IActionResult result = this._userController.Register(registerWebModel).Result; @@ -105,9 +117,15 @@ namespace DevHive.Web.Tests UserName = USERNAME }; - this._userServiceMock.Setup(p => p.GetUserById(It.IsAny())).Returns(Task.FromResult(userServiceModel)); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(userWebModel); + this._userServiceMock + .Setup(p => p.GetUserById(It.IsAny())) + .Returns(Task.FromResult(userServiceModel)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(userWebModel); IActionResult result = this._userController.GetById(id, null).Result; @@ -122,7 +140,9 @@ namespace DevHive.Web.Tests [Test] public void GetById_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(false); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(false); IActionResult result = this._userController.GetById(Guid.NewGuid(), null).Result; @@ -141,8 +161,12 @@ namespace DevHive.Web.Tests UserName = USERNAME }; - this._userServiceMock.Setup(p => p.GetUserByUsername(It.IsAny())).Returns(Task.FromResult(userServiceModel)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(userWebModel); + this._userServiceMock + .Setup(p => p.GetUserByUsername(It.IsAny())) + .Returns(Task.FromResult(userServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(userWebModel); IActionResult result = this._userController.GetUser(null).Result; @@ -173,9 +197,15 @@ namespace DevHive.Web.Tests UserName = USERNAME }; - this._userServiceMock.Setup(p => p.UpdateUser(It.IsAny())).Returns(Task.FromResult(userServiceModel)); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateUserServiceModel); + this._userServiceMock + .Setup(p => p.UpdateUser(It.IsAny())) + .Returns(Task.FromResult(userServiceModel)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateUserServiceModel); IActionResult result = this._userController.Update(id, updateUserWebModel, null).Result; @@ -189,8 +219,12 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._userServiceMock.Setup(p => p.DeleteUser(It.IsAny())).Returns(Task.FromResult(true)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._userServiceMock + .Setup(p => p.DeleteUser(It.IsAny())) + .Returns(Task.FromResult(true)); IActionResult result = this._userController.Delete(id, null).Result; @@ -203,8 +237,12 @@ namespace DevHive.Web.Tests string message = "Could not delete User"; Guid id = Guid.NewGuid(); - this._jwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this._userServiceMock.Setup(p => p.DeleteUser(It.IsAny())).Returns(Task.FromResult(false)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._userServiceMock + .Setup(p => p.DeleteUser(It.IsAny())) + .Returns(Task.FromResult(false)); IActionResult result = this._userController.Delete(id, null).Result; -- cgit v1.2.3 From dec1f686cdd1bdd2b1b9a2fe0925369624f46aba Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 11:54:47 +0200 Subject: Made all Returns(Task.FromResult) into ReturnsAsync in Web layer tests --- .../DevHive.Web.Tests/CommentController.Tests.cs | 33 ++++++++++---------- src/Web/DevHive.Web.Tests/FeedController.Tests.cs | 4 +-- .../DevHive.Web.Tests/LanguageController.Tests.cs | 17 +++++------ src/Web/DevHive.Web.Tests/PostController.Tests.cs | 35 +++++++++++----------- src/Web/DevHive.Web.Tests/RoleController.Tests.cs | 17 +++++------ .../TechnologyController.Tests.cs | 17 +++++------ src/Web/DevHive.Web.Tests/UserController.Tests.cs | 17 +++++------ 7 files changed, 67 insertions(+), 73 deletions(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs index 4e1715c..830677e 100644 --- a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Threading.Tasks; using AutoMapper; using DevHive.Common.Jwt.Interfaces; using DevHive.Services.Interfaces; @@ -52,13 +51,13 @@ namespace DevHive.Web.Tests .Returns(createCommentServiceModel); this._commentServiceMock .Setup(p => p.AddComment(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(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)); + .ReturnsAsync(true); IActionResult result = this._commentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; @@ -94,13 +93,13 @@ namespace DevHive.Web.Tests .Returns(createCommentServiceModel); this._commentServiceMock .Setup(p => p.AddComment(It.IsAny())) - .Returns(Task.FromResult(Guid.Empty)); + .ReturnsAsync(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)); + .ReturnsAsync(true); IActionResult result = this._commentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; @@ -125,7 +124,7 @@ namespace DevHive.Web.Tests .Returns(true); this._commentServiceMock .Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._commentController.AddComment(Guid.NewGuid(), createCommentWebModel, null).Result; @@ -152,7 +151,7 @@ namespace DevHive.Web.Tests .Returns(true); this._commentServiceMock .Setup(p => p.GetCommentById(It.IsAny())) - .Returns(Task.FromResult(readCommentServiceModel)); + .ReturnsAsync(readCommentServiceModel); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(readCommentWebModel); @@ -184,13 +183,13 @@ namespace DevHive.Web.Tests this._commentServiceMock .Setup(p => p.UpdateComment(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(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)); + .ReturnsAsync(true); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updateCommentServiceModel); @@ -221,13 +220,13 @@ namespace DevHive.Web.Tests this._commentServiceMock .Setup(p => p.UpdateComment(It.IsAny())) - .Returns(Task.FromResult(Guid.Empty)); + .ReturnsAsync(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)); + .ReturnsAsync(true); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updateCommentServiceModel); @@ -252,7 +251,7 @@ namespace DevHive.Web.Tests 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)); + // this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).ReturnsAsync(false)); IActionResult result = this._commentController.UpdateComment(Guid.Empty, updateCommentWebModel, null).Result; @@ -268,13 +267,13 @@ namespace DevHive.Web.Tests this._commentServiceMock .Setup(p => p.DeleteComment(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(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)); + .ReturnsAsync(true); IActionResult result = this._commentController.DeleteComment(id, null).Result; @@ -289,13 +288,13 @@ namespace DevHive.Web.Tests this._commentServiceMock .Setup(p => p.DeleteComment(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(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)); + .ReturnsAsync(true); IActionResult result = this._commentController.DeleteComment(id, null).Result; @@ -315,7 +314,7 @@ namespace DevHive.Web.Tests .Returns(true); this._commentServiceMock .Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._commentController.DeleteComment(Guid.Empty, null).Result; diff --git a/src/Web/DevHive.Web.Tests/FeedController.Tests.cs b/src/Web/DevHive.Web.Tests/FeedController.Tests.cs index 7a7fd8d..3af2b48 100644 --- a/src/Web/DevHive.Web.Tests/FeedController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/FeedController.Tests.cs @@ -50,7 +50,7 @@ namespace DevHive.Web.Tests this._feedServiceMock .Setup(p => p.GetPage(It.IsAny())) - .Returns(Task.FromResult(readPageServiceModel)); + .ReturnsAsync(readPageServiceModel); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(getPageServiceModel); @@ -88,7 +88,7 @@ namespace DevHive.Web.Tests this._feedServiceMock .Setup(p => p.GetUserPage(It.IsAny())) - .Returns(Task.FromResult(readPageServiceModel)); + .ReturnsAsync(readPageServiceModel); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(getPageServiceModel); diff --git a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs index de882fc..34f1fc5 100644 --- a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Threading.Tasks; using AutoMapper; using DevHive.Services.Interfaces; using DevHive.Services.Models.Language; @@ -12,7 +11,7 @@ using NUnit.Framework; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] public class LanguageControllerTests { const string NAME = "Gosho Trapov"; @@ -47,7 +46,7 @@ namespace DevHive.Web.Tests .Returns(createLanguageServiceModel); this._languageServiceMock .Setup(p => p.CreateLanguage(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); IActionResult result = this._languageController.Create(createLanguageWebModel).Result; @@ -83,7 +82,7 @@ namespace DevHive.Web.Tests .Returns(createTechnologyServiceModel); this._languageServiceMock .Setup(p => p.CreateLanguage(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); IActionResult result = this._languageController.Create(createTechnologyWebModel).Result; @@ -113,7 +112,7 @@ namespace DevHive.Web.Tests this._languageServiceMock .Setup(p => p.GetLanguageById(It.IsAny())) - .Returns(Task.FromResult(readLanguageServiceModel)); + .ReturnsAsync(readLanguageServiceModel); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(readLanguageWebModel); @@ -145,7 +144,7 @@ namespace DevHive.Web.Tests this._languageServiceMock .Setup(p => p.UpdateLanguage(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updateLanguageServiceModel); @@ -171,7 +170,7 @@ namespace DevHive.Web.Tests this._languageServiceMock .Setup(p => p.UpdateLanguage(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updateLanguageServiceModel); @@ -194,7 +193,7 @@ namespace DevHive.Web.Tests this._languageServiceMock .Setup(p => p.DeleteLanguage(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._languageController.Delete(id).Result; @@ -209,7 +208,7 @@ namespace DevHive.Web.Tests this._languageServiceMock .Setup(p => p.DeleteLanguage(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._languageController.Delete(id).Result; diff --git a/src/Web/DevHive.Web.Tests/PostController.Tests.cs b/src/Web/DevHive.Web.Tests/PostController.Tests.cs index 384a92a..93cce1d 100644 --- a/src/Web/DevHive.Web.Tests/PostController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/PostController.Tests.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Threading.Tasks; using AutoMapper; using DevHive.Common.Jwt.Interfaces; using DevHive.Services.Interfaces; @@ -13,7 +12,7 @@ using NUnit.Framework; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] public class PostControllerTests { const string MESSAGE = "Gosho Trapov"; @@ -50,13 +49,13 @@ namespace DevHive.Web.Tests .Returns(createPostServiceModel); this._postServiceMock .Setup(p => p.CreatePost(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); this._jwtServiceMock .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) .Returns(true); this._postServiceMock .Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._postController.Create(Guid.Empty, createPostWebModel, null).Result; @@ -92,13 +91,13 @@ namespace DevHive.Web.Tests .Returns(createTechnologyServiceModel); this._postServiceMock .Setup(p => p.CreatePost(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); this._jwtServiceMock .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) .Returns(true); this._postServiceMock .Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._postController.Create(Guid.Empty, createTechnologyWebModel, null).Result; @@ -120,7 +119,7 @@ namespace DevHive.Web.Tests this._postServiceMock .Setup(p => p.ValidateJwtForCreating(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._postController.Create(Guid.NewGuid(), createPostWebModel, null).Result; @@ -145,7 +144,7 @@ namespace DevHive.Web.Tests this._postServiceMock .Setup(p => p.GetPostById(It.IsAny())) - .Returns(Task.FromResult(readPostServiceModel)); + .ReturnsAsync(readPostServiceModel); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(readPostWebModel); @@ -177,7 +176,7 @@ namespace DevHive.Web.Tests this._postServiceMock .Setup(p => p.UpdatePost(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updatePostServiceModel); @@ -186,7 +185,7 @@ namespace DevHive.Web.Tests .Returns(true); this._postServiceMock .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._postController.Update(id, updatePostWebModel, null).Result; @@ -209,7 +208,7 @@ namespace DevHive.Web.Tests this._postServiceMock .Setup(p => p.UpdatePost(It.IsAny())) - .Returns(Task.FromResult(Guid.Empty)); + .ReturnsAsync(Guid.Empty); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updatePostServiceModel); @@ -218,7 +217,7 @@ namespace DevHive.Web.Tests .Returns(true); this._postServiceMock .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._postController.Update(id, updatePostWebModel, null).Result; Assert.IsInstanceOf(result); @@ -239,7 +238,7 @@ namespace DevHive.Web.Tests this._postServiceMock .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._postController.Update(Guid.Empty, updatePostWebModel, null).Result; @@ -255,13 +254,13 @@ namespace DevHive.Web.Tests this._postServiceMock .Setup(p => p.DeletePost(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); this._jwtServiceMock .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) .Returns(true); this._postServiceMock .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._postController.Delete(id, null).Result; @@ -276,13 +275,13 @@ namespace DevHive.Web.Tests this._postServiceMock .Setup(p => p.DeletePost(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); this._jwtServiceMock .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) .Returns(true); this._postServiceMock .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._postController.Delete(id, null).Result; @@ -299,7 +298,7 @@ namespace DevHive.Web.Tests { this._postServiceMock .Setup(p => p.ValidateJwtForPost(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._postController.Delete(Guid.Empty, null).Result; diff --git a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs index 0f835c1..0e19221 100644 --- a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Threading.Tasks; using AutoMapper; using DevHive.Services.Interfaces; using DevHive.Services.Models.Role; @@ -12,7 +11,7 @@ using NUnit.Framework; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] public class RoleControllerTests { const string NAME = "Gosho Trapov"; @@ -47,7 +46,7 @@ namespace DevHive.Web.Tests .Returns(createRoleServiceModel); this._roleServiceMock .Setup(p => p.CreateRole(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); IActionResult result = this._roleController.Create(createRoleWebModel).Result; @@ -83,7 +82,7 @@ namespace DevHive.Web.Tests .Returns(createTechnologyServiceModel); this._roleServiceMock .Setup(p => p.CreateRole(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); IActionResult result = this._roleController.Create(createTechnologyWebModel).Result; @@ -113,7 +112,7 @@ namespace DevHive.Web.Tests this._roleServiceMock .Setup(p => p.GetRoleById(It.IsAny())) - .Returns(Task.FromResult(roleServiceModel)); + .ReturnsAsync(roleServiceModel); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(roleWebModel); @@ -145,7 +144,7 @@ namespace DevHive.Web.Tests this._roleServiceMock .Setup(p => p.UpdateRole(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updateRoleServiceModel); @@ -171,7 +170,7 @@ namespace DevHive.Web.Tests this._roleServiceMock .Setup(p => p.UpdateRole(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updateRoleServiceModel); @@ -194,7 +193,7 @@ namespace DevHive.Web.Tests this._roleServiceMock .Setup(p => p.DeleteRole(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._roleController.Delete(id).Result; @@ -209,7 +208,7 @@ namespace DevHive.Web.Tests this._roleServiceMock .Setup(p => p.DeleteRole(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._roleController.Delete(id).Result; diff --git a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs index 76d291d..06e1ea2 100644 --- a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs @@ -8,11 +8,10 @@ using Moq; using NUnit.Framework; using System; using System.Linq; -using System.Threading.Tasks; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] public class TechnologyControllerTests { const string NAME = "Gosho Trapov"; @@ -49,7 +48,7 @@ namespace DevHive.Web.Tests .Returns(createTechnologyServiceModel); this._technologyServiceMock .Setup(p => p.CreateTechnology(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); IActionResult result = this._technologyController.Create(createTechnologyWebModel).Result; @@ -85,7 +84,7 @@ namespace DevHive.Web.Tests .Returns(createTechnologyServiceModel); this._technologyServiceMock .Setup(p => p.CreateTechnology(It.IsAny())) - .Returns(Task.FromResult(id)); + .ReturnsAsync(id); IActionResult result = this._technologyController.Create(createTechnologyWebModel).Result; @@ -115,7 +114,7 @@ namespace DevHive.Web.Tests this._technologyServiceMock .Setup(p => p.GetTechnologyById(It.IsAny())) - .Returns(Task.FromResult(readTechnologyServiceModel)); + .ReturnsAsync(readTechnologyServiceModel); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(readTechnologyWebModel); @@ -147,7 +146,7 @@ namespace DevHive.Web.Tests this._technologyServiceMock .Setup(p => p.UpdateTechnology(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updateTechnologyServiceModel); @@ -173,7 +172,7 @@ namespace DevHive.Web.Tests this._technologyServiceMock .Setup(p => p.UpdateTechnology(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(updateTechnologyServiceModel); @@ -196,7 +195,7 @@ namespace DevHive.Web.Tests this._technologyServiceMock .Setup(p => p.DeleteTechnology(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._technologyController.Delete(id).Result; @@ -211,7 +210,7 @@ namespace DevHive.Web.Tests this._technologyServiceMock .Setup(p => p.DeleteTechnology(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._technologyController.Delete(id).Result; diff --git a/src/Web/DevHive.Web.Tests/UserController.Tests.cs b/src/Web/DevHive.Web.Tests/UserController.Tests.cs index ad7bdd9..10d3c6b 100644 --- a/src/Web/DevHive.Web.Tests/UserController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/UserController.Tests.cs @@ -1,5 +1,4 @@ using System; -using System.Threading.Tasks; using AutoMapper; using DevHive.Common.Jwt.Interfaces; using DevHive.Common.Models.Identity; @@ -13,7 +12,7 @@ using NUnit.Framework; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] public class UserControllerTests { const string USERNAME = "Gosho Trapov"; @@ -55,7 +54,7 @@ namespace DevHive.Web.Tests .Returns(tokenWebModel); this._userServiceMock .Setup(p => p.LoginUser(It.IsAny())) - .Returns(Task.FromResult(tokenModel)); + .ReturnsAsync(tokenModel); IActionResult result = this._userController.Login(loginWebModel).Result; @@ -89,7 +88,7 @@ namespace DevHive.Web.Tests .Returns(tokenWebModel); this._userServiceMock .Setup(p => p.RegisterUser(It.IsAny())) - .Returns(Task.FromResult(tokenModel)); + .ReturnsAsync(tokenModel); IActionResult result = this._userController.Register(registerWebModel).Result; @@ -119,7 +118,7 @@ namespace DevHive.Web.Tests this._userServiceMock .Setup(p => p.GetUserById(It.IsAny())) - .Returns(Task.FromResult(userServiceModel)); + .ReturnsAsync(userServiceModel); this._jwtServiceMock .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) .Returns(true); @@ -163,7 +162,7 @@ namespace DevHive.Web.Tests this._userServiceMock .Setup(p => p.GetUserByUsername(It.IsAny())) - .Returns(Task.FromResult(userServiceModel)); + .ReturnsAsync(userServiceModel); this._mapperMock .Setup(p => p.Map(It.IsAny())) .Returns(userWebModel); @@ -199,7 +198,7 @@ namespace DevHive.Web.Tests this._userServiceMock .Setup(p => p.UpdateUser(It.IsAny())) - .Returns(Task.FromResult(userServiceModel)); + .ReturnsAsync(userServiceModel); this._jwtServiceMock .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) .Returns(true); @@ -224,7 +223,7 @@ namespace DevHive.Web.Tests .Returns(true); this._userServiceMock .Setup(p => p.DeleteUser(It.IsAny())) - .Returns(Task.FromResult(true)); + .ReturnsAsync(true); IActionResult result = this._userController.Delete(id, null).Result; @@ -242,7 +241,7 @@ namespace DevHive.Web.Tests .Returns(true); this._userServiceMock .Setup(p => p.DeleteUser(It.IsAny())) - .Returns(Task.FromResult(false)); + .ReturnsAsync(false); IActionResult result = this._userController.Delete(id, null).Result; -- cgit v1.2.3 From e68181d5452f8e2c553c1eb36e689bab1ae080e3 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sun, 14 Mar 2021 21:16:53 +0200 Subject: added documentaion for rating repository --- .../DevHive.Data/Repositories/RatingRepository.cs | 22 ++++++++++++++++++++++ src/Web/DevHive.Web/Startup.cs | 1 - 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Web') diff --git a/src/Data/DevHive.Data/Repositories/RatingRepository.cs b/src/Data/DevHive.Data/Repositories/RatingRepository.cs index 1784144..e4a5d5d 100644 --- a/src/Data/DevHive.Data/Repositories/RatingRepository.cs +++ b/src/Data/DevHive.Data/Repositories/RatingRepository.cs @@ -27,6 +27,11 @@ namespace DevHive.Data.Repositories .Include(x => x.Post) .FirstOrDefaultAsync(x => x.Id == id); } + /// + /// Gets all the ratings for a psot. + /// + /// Id of the post. + /// public async Task> GetRatingsByPostId(Guid postId) { return await this._context.Rating @@ -34,12 +39,24 @@ namespace DevHive.Data.Repositories .Include(x => x.Post) .Where(x => x.Post.Id == postId).ToListAsync(); } + /// + /// Checks if a user rated a given post. + /// + /// Id of the user. + /// Id of the psot. + /// True if the user has already rated the post and false if he hasn't. public async Task UserRatedPost(Guid userId, Guid postId) { return await this._context.Rating .Where(x => x.Post.Id == postId) .AnyAsync(x => x.User.Id == userId); } + /// + /// Gets a rating by the post to which the rating corresponds and the user who created it. + /// + /// Id of the user. + /// Id of the post. + /// Rating for the given post by the given user. public async Task GetRatingByUserAndPostId(Guid userId, Guid postId) { return await this._context.Rating @@ -48,6 +65,11 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(x => x.Post.Id == postId && x.User.Id == userId); } + /// + /// Checks if a given rating already exist + /// + /// Id of the rating + /// True if the rating exists and false if it does not. public async Task DoesRatingExist(Guid id) { return await this._context.Rating diff --git a/src/Web/DevHive.Web/Startup.cs b/src/Web/DevHive.Web/Startup.cs index 40f674d..1c714ec 100644 --- a/src/Web/DevHive.Web/Startup.cs +++ b/src/Web/DevHive.Web/Startup.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using DevHive.Web.Configurations.Extensions; using Newtonsoft.Json; -using System.Threading.Tasks; namespace DevHive.Web { -- cgit v1.2.3 From 76f71bb8cab45922f3e4999253a1567a0e4af3db Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 21:39:37 +0200 Subject: Updated rating tests to follow our current code style standards --- .../DevHive.Data.Tests/RatingRepository.Tests.cs | 46 ++--- .../DevHive.Services.Tests/RatingService.Tests.cs | 210 ++++++++++++++------- .../DevHive.Web.Tests/RatingController.Tests.cs | 118 ++++++++---- 3 files changed, 247 insertions(+), 127 deletions(-) (limited to 'src/Web') diff --git a/src/Data/DevHive.Data.Tests/RatingRepository.Tests.cs b/src/Data/DevHive.Data.Tests/RatingRepository.Tests.cs index 17616fe..2da90d9 100644 --- a/src/Data/DevHive.Data.Tests/RatingRepository.Tests.cs +++ b/src/Data/DevHive.Data.Tests/RatingRepository.Tests.cs @@ -12,8 +12,8 @@ namespace DevHive.Data.Tests [TestFixture] public class RatingRepositoryTests { - private DevHiveContext Context { get; set; } - private RatingRepository RatingRepository { get; set; } + private DevHiveContext _context; + private RatingRepository _ratingRepository; #region Setups [SetUp] @@ -22,14 +22,14 @@ namespace DevHive.Data.Tests var optionsBuilder = new DbContextOptionsBuilder() .UseInMemoryDatabase(databaseName: "DevHive_Test_Database"); - this.Context = new DevHiveContext(optionsBuilder.Options); - this.RatingRepository = new RatingRepository(this.Context, null); + this._context = new DevHiveContext(optionsBuilder.Options); + this._ratingRepository = new RatingRepository(this._context, null); } [TearDown] public void TearDown() { - this.Context.Database.EnsureDeleted(); + this._context.Database.EnsureDeleted(); } #endregion @@ -40,7 +40,7 @@ namespace DevHive.Data.Tests Guid ratingId = Guid.NewGuid(); await AddDummyRating(ratingId); - Rating ratingResult = await this.RatingRepository.GetByIdAsync(ratingId); + Rating ratingResult = await this._ratingRepository.GetByIdAsync(ratingId); Assert.AreEqual(ratingResult.Id, ratingId); } @@ -48,7 +48,7 @@ namespace DevHive.Data.Tests [Test] public async Task GetByIdAsync_ReturnsNull_IfRatingDoesNotExist() { - Rating ratingResult = await this.RatingRepository.GetByIdAsync(Guid.NewGuid()); + Rating ratingResult = await this._ratingRepository.GetByIdAsync(Guid.NewGuid()); Assert.IsNull(ratingResult); } @@ -63,7 +63,7 @@ namespace DevHive.Data.Tests await AddDummyRating(Guid.NewGuid(), postId); await AddDummyRating(Guid.NewGuid(), postId); - List result = await this.RatingRepository.GetRatingsByPostId(postId); + List result = await this._ratingRepository.GetRatingsByPostId(postId); Assert.IsNotEmpty(result); } @@ -71,7 +71,7 @@ namespace DevHive.Data.Tests [Test] public async Task GetRatingsByPostId_ReturnsEmptyList_WhenThereAreNoRatings() { - List result = await this.RatingRepository.GetRatingsByPostId(Guid.NewGuid()); + List result = await this._ratingRepository.GetRatingsByPostId(Guid.NewGuid()); Assert.IsEmpty(result); } @@ -88,7 +88,7 @@ namespace DevHive.Data.Tests await AddDummyUser(userId); await AddDummyRating(ratingId, postId, userId); - Rating result = await this.RatingRepository.GetRatingByUserAndPostId(userId, postId); + Rating result = await this._ratingRepository.GetRatingByUserAndPostId(userId, postId); Assert.AreEqual(result.Id, ratingId); } @@ -96,7 +96,7 @@ namespace DevHive.Data.Tests [Test] public async Task GetRatingByUserAndPostId_ReturnsNull_WhenRatingDoesNotExist() { - Rating result = await this.RatingRepository.GetRatingByUserAndPostId(Guid.NewGuid(), Guid.NewGuid()); + Rating result = await this._ratingRepository.GetRatingByUserAndPostId(Guid.NewGuid(), Guid.NewGuid()); Assert.IsNull(result); } @@ -112,7 +112,7 @@ namespace DevHive.Data.Tests await AddDummyUser(userId); await AddDummyRating(Guid.NewGuid(), postId, userId); - bool result = await this.RatingRepository.UserRatedPost(userId, postId); + bool result = await this._ratingRepository.UserRatedPost(userId, postId); Assert.IsTrue(result); } @@ -120,7 +120,7 @@ namespace DevHive.Data.Tests [Test] public async Task UserRatedPost_ReturnsFalse_WhenUserHasNotRatedPost() { - bool result = await this.RatingRepository.UserRatedPost(Guid.NewGuid(), Guid.NewGuid()); + bool result = await this._ratingRepository.UserRatedPost(Guid.NewGuid(), Guid.NewGuid()); Assert.IsFalse(result); } @@ -133,7 +133,7 @@ namespace DevHive.Data.Tests Guid ratingId = Guid.NewGuid(); await AddDummyRating(ratingId); - bool result = await this.RatingRepository.DoesRatingExist(ratingId); + bool result = await this._ratingRepository.DoesRatingExist(ratingId); Assert.IsTrue(result); } @@ -141,7 +141,7 @@ namespace DevHive.Data.Tests [Test] public async Task DoesRatingExist_ReturnsFalse_WhenRatingDoesNotExist() { - bool result = await this.RatingRepository.DoesRatingExist(Guid.NewGuid()); + bool result = await this._ratingRepository.DoesRatingExist(Guid.NewGuid()); Assert.IsFalse(result); } @@ -153,12 +153,12 @@ namespace DevHive.Data.Tests Rating rating = new Rating { Id = ratingId, - Post = this.Context.Posts.FirstOrDefault(x => x.Id == postId), - User = this.Context.Users.FirstOrDefault(x => x.Id == userId) + Post = this._context.Posts.FirstOrDefault(x => x.Id == postId), + User = this._context.Users.FirstOrDefault(x => x.Id == userId) }; - await this.Context.Rating.AddAsync(rating); - await this.Context.SaveChangesAsync(); + await this._context.Rating.AddAsync(rating); + await this._context.SaveChangesAsync(); } private async Task AddDummyPost(Guid postId) @@ -169,8 +169,8 @@ namespace DevHive.Data.Tests Message = "Never gonna give you up" }; - await this.Context.Posts.AddAsync(post); - await this.Context.SaveChangesAsync(); + await this._context.Posts.AddAsync(post); + await this._context.SaveChangesAsync(); } private async Task AddDummyUser(Guid userId) @@ -180,8 +180,8 @@ namespace DevHive.Data.Tests Id = userId }; - await this.Context.Users.AddAsync(user); - await this.Context.SaveChangesAsync(); + await this._context.Users.AddAsync(user); + await this._context.SaveChangesAsync(); } #endregion } diff --git a/src/Services/DevHive.Services.Tests/RatingService.Tests.cs b/src/Services/DevHive.Services.Tests/RatingService.Tests.cs index 89c1a2e..5f84530 100644 --- a/src/Services/DevHive.Services.Tests/RatingService.Tests.cs +++ b/src/Services/DevHive.Services.Tests/RatingService.Tests.cs @@ -13,21 +13,21 @@ namespace DevHive.Services.Tests [TestFixture] public class RatingServiceTests { - private Mock PostRepositoryMock { get; set; } - private Mock RatingRepositoryMock { get; set; } - private Mock UserRepositoryMock { get; set; } - private Mock MapperMock { get; set; } - private RatingService RatingService { get; set; } + private Mock _postRepositoryMock; + private Mock _ratingRepositoryMock; + private Mock _userRepositoryMock; + private Mock _mapperMock; + private RatingService _ratingService; #region SetUps [SetUp] public void SetUp() { - this.PostRepositoryMock = new Mock(); - this.RatingRepositoryMock = new Mock(); - this.UserRepositoryMock = new Mock(); - this.MapperMock = new Mock(); - this.RatingService = new RatingService(this.PostRepositoryMock.Object, this.RatingRepositoryMock.Object, this.UserRepositoryMock.Object, this.MapperMock.Object); + this._postRepositoryMock = new Mock(); + this._ratingRepositoryMock = new Mock(); + this._userRepositoryMock = new Mock(); + this._mapperMock = new Mock(); + this._ratingService = new RatingService(this._postRepositoryMock.Object, this._ratingRepositoryMock.Object, this._userRepositoryMock.Object, this._mapperMock.Object); } #endregion @@ -59,15 +59,29 @@ namespace DevHive.Services.Tests Id = postId }; - this.PostRepositoryMock.Setup(p => p.DoesPostExist(It.IsAny())).Returns(Task.FromResult(true)); - this.RatingRepositoryMock.Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); - this.PostRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(post)); - this.RatingRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(true)); - this.RatingRepositoryMock.Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())).Returns(Task.FromResult(rating)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(rating); - - Guid result = await this.RatingService.RatePost(createRatingServiceModel); + this._postRepositoryMock + .Setup(p => p.DoesPostExist(It.IsAny())) + .ReturnsAsync(true); + this._ratingRepositoryMock + .Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())) + .ReturnsAsync(false); + this._userRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .ReturnsAsync(user); + this._postRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .ReturnsAsync(post); + this._ratingRepositoryMock + .Setup(p => p.AddAsync(It.IsAny())) + .ReturnsAsync(true); + this._ratingRepositoryMock + .Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())) + .ReturnsAsync(rating); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(rating); + + Guid result = await this._ratingService.RatePost(createRatingServiceModel); Assert.AreEqual(id, result); } @@ -99,14 +113,26 @@ namespace DevHive.Services.Tests Id = postId }; - this.PostRepositoryMock.Setup(p => p.DoesPostExist(It.IsAny())).Returns(Task.FromResult(true)); - this.RatingRepositoryMock.Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); - this.PostRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(post)); - this.RatingRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(false)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(rating); - - Guid result = await this.RatingService.RatePost(createRatingServiceModel); + this._postRepositoryMock + .Setup(p => p.DoesPostExist(It.IsAny())) + .ReturnsAsync(true); + this._ratingRepositoryMock + .Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())) + .ReturnsAsync(false); + this._userRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .ReturnsAsync(user); + this._postRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .ReturnsAsync(post); + this._ratingRepositoryMock + .Setup(p => p.AddAsync(It.IsAny())) + .ReturnsAsync(false); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(rating); + + Guid result = await this._ratingService.RatePost(createRatingServiceModel); Assert.AreEqual(result, Guid.Empty); } @@ -134,10 +160,14 @@ namespace DevHive.Services.Tests IsLike = isLike }; - this.RatingRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(rating)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingServiceModel); + this._ratingRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .ReturnsAsync(rating); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readRatingServiceModel); - ReadRatingServiceModel result = await this.RatingService.GetRatingById(id); + ReadRatingServiceModel result = await this._ratingService.GetRatingById(id); Assert.AreEqual(isLike, result.IsLike); } @@ -146,9 +176,11 @@ namespace DevHive.Services.Tests public void GetRatingById_ThrowsException_WhenRatingDoesNotExist() { string exceptionMessage = "The rating does not exist"; - this.RatingRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(null)); + this._ratingRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .Returns(Task.FromResult(null)); - Exception ex = Assert.ThrowsAsync(() => this.RatingService.GetRatingById(Guid.Empty)); + Exception ex = Assert.ThrowsAsync(() => this._ratingService.GetRatingById(Guid.Empty)); Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } @@ -174,10 +206,14 @@ namespace DevHive.Services.Tests IsLike = isLike }; - this.RatingRepositoryMock.Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())).Returns(Task.FromResult(rating)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingServiceModel); + this._ratingRepositoryMock + .Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())) + .ReturnsAsync(rating); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readRatingServiceModel); - ReadRatingServiceModel result = await this.RatingService.GetRatingByPostAndUser(user.Id, Guid.Empty); + ReadRatingServiceModel result = await this._ratingService.GetRatingByPostAndUser(user.Id, Guid.Empty); Assert.AreEqual(isLike, result.IsLike); } @@ -186,9 +222,11 @@ namespace DevHive.Services.Tests public void GetRatingByPostAndUser_ThrowsException_WhenRatingDoesNotExist() { string exceptionMessage = "The rating does not exist"; - this.RatingRepositoryMock.Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())).Returns(Task.FromResult(null)); + this._ratingRepositoryMock + .Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(null)); - Exception ex = Assert.ThrowsAsync(() => this.RatingService.GetRatingById(Guid.Empty)); + Exception ex = Assert.ThrowsAsync(() => this._ratingService.GetRatingById(Guid.Empty)); Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } @@ -221,13 +259,23 @@ namespace DevHive.Services.Tests IsLike = isLike }; - this.RatingRepositoryMock.Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())).Returns(Task.FromResult(rating)); - this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); - this.RatingRepositoryMock.Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - this.RatingRepositoryMock.Setup(p => p.EditAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingServiceModel); - - ReadRatingServiceModel result = await this.RatingService.UpdateRating(updateRatingServiceModel); + this._ratingRepositoryMock + .Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())) + .ReturnsAsync(rating); + this._userRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .ReturnsAsync(user); + this._ratingRepositoryMock + .Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())) + .ReturnsAsync(true); + this._ratingRepositoryMock + .Setup(p => p.EditAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(true); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readRatingServiceModel); + + ReadRatingServiceModel result = await this._ratingService.UpdateRating(updateRatingServiceModel); Assert.AreEqual(result, readRatingServiceModel); } @@ -258,12 +306,20 @@ namespace DevHive.Services.Tests IsLike = isLike }; - this.RatingRepositoryMock.Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())).Returns(Task.FromResult(rating)); - this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); - this.RatingRepositoryMock.Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); - this.RatingRepositoryMock.Setup(p => p.EditAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - - ReadRatingServiceModel result = await this.RatingService.UpdateRating(updateRatingServiceModel); + this._ratingRepositoryMock + .Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())) + .ReturnsAsync(rating); + this._userRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .ReturnsAsync(user); + this._ratingRepositoryMock + .Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())) + .ReturnsAsync(true); + this._ratingRepositoryMock + .Setup(p => p.EditAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(false); + + ReadRatingServiceModel result = await this._ratingService.UpdateRating(updateRatingServiceModel); Assert.IsNull(result); } @@ -278,9 +334,11 @@ namespace DevHive.Services.Tests IsLike = true }; - this.RatingRepositoryMock.Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())).Returns(Task.FromResult(null)); + this._ratingRepositoryMock + .Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(null)); - Exception ex = Assert.ThrowsAsync(() => this.RatingService.UpdateRating(updateRatingServiceModel)); + Exception ex = Assert.ThrowsAsync(() => this._ratingService.UpdateRating(updateRatingServiceModel)); Assert.AreEqual(ex.Message, exceptionMessage); } @@ -307,11 +365,17 @@ namespace DevHive.Services.Tests User = user }; - this.RatingRepositoryMock.Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())).Returns(Task.FromResult(rating)); - this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(user)); - this.RatingRepositoryMock.Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + this._ratingRepositoryMock + .Setup(p => p.GetRatingByUserAndPostId(It.IsAny(), It.IsAny())) + .ReturnsAsync(rating); + this._userRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .ReturnsAsync(user); + this._ratingRepositoryMock + .Setup(p => p.UserRatedPost(It.IsAny(), It.IsAny())) + .ReturnsAsync(false); - Exception ex = Assert.ThrowsAsync(() => this.RatingService.UpdateRating(updateRatingServiceModel)); + Exception ex = Assert.ThrowsAsync(() => this._ratingService.UpdateRating(updateRatingServiceModel)); Assert.AreEqual(ex.Message, exceptionMessage); } @@ -327,11 +391,17 @@ namespace DevHive.Services.Tests Id = ratingId }; - this.RatingRepositoryMock.Setup(p => p.DoesRatingExist(It.IsAny())).Returns(Task.FromResult(true)); - this.RatingRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(null)); - this.RatingRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny())).Returns(Task.FromResult(true)); + this._ratingRepositoryMock + .Setup(p => p.DoesRatingExist(It.IsAny())) + .ReturnsAsync(true); + this._ratingRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .Returns(Task.FromResult(null)); + this._ratingRepositoryMock + .Setup(p => p.DeleteAsync(It.IsAny())) + .ReturnsAsync(true); - bool result = await this.RatingService.DeleteRating(ratingId); + bool result = await this._ratingService.DeleteRating(ratingId); Assert.IsTrue(result); } @@ -345,11 +415,17 @@ namespace DevHive.Services.Tests Id = ratingId }; - this.RatingRepositoryMock.Setup(p => p.DoesRatingExist(It.IsAny())).Returns(Task.FromResult(true)); - this.RatingRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(null)); - this.RatingRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny())).Returns(Task.FromResult(false)); + this._ratingRepositoryMock + .Setup(p => p.DoesRatingExist(It.IsAny())) + .ReturnsAsync(true); + this._ratingRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .Returns(Task.FromResult(null)); + this._ratingRepositoryMock + .Setup(p => p.DeleteAsync(It.IsAny())) + .ReturnsAsync(false); - bool result = await this.RatingService.DeleteRating(ratingId); + bool result = await this._ratingService.DeleteRating(ratingId); Assert.IsFalse(result); } @@ -359,9 +435,11 @@ namespace DevHive.Services.Tests { string exceptionMessage = "Rating does not exist!"; - this.RatingRepositoryMock.Setup(p => p.DoesRatingExist(It.IsAny())).Returns(Task.FromResult(false)); + this._ratingRepositoryMock + .Setup(p => p.DoesRatingExist(It.IsAny())) + .ReturnsAsync(false); - Exception ex = Assert.ThrowsAsync(() => this.RatingService.DeleteRating(Guid.Empty)); + Exception ex = Assert.ThrowsAsync(() => this._ratingService.DeleteRating(Guid.Empty)); Assert.AreEqual(ex.Message, exceptionMessage); } diff --git a/src/Web/DevHive.Web.Tests/RatingController.Tests.cs b/src/Web/DevHive.Web.Tests/RatingController.Tests.cs index dd8954f..c7340a6 100644 --- a/src/Web/DevHive.Web.Tests/RatingController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/RatingController.Tests.cs @@ -16,18 +16,18 @@ namespace DevHive.Web.Tests [TestFixture] public class RatingControllerTests { - private Mock RatingServiceMock { get; set; } - private Mock MapperMock { get; set; } - private Mock JwtServiceMock { get; set; } - private RatingController RatingController { get; set; } + private Mock _ratingServiceMock; + private Mock _mapperMock; + private Mock _jwtServiceMock; + private RatingController _ratingController; [SetUp] public void SetUp() { - this.RatingServiceMock = new Mock(); - this.MapperMock = new Mock(); - this.JwtServiceMock = new Mock(); - this.RatingController = new RatingController(this.RatingServiceMock.Object, this.MapperMock.Object, this.JwtServiceMock.Object); + this._ratingServiceMock = new Mock(); + this._mapperMock = new Mock(); + this._jwtServiceMock = new Mock(); + this._ratingController = new RatingController(this._ratingServiceMock.Object, this._mapperMock.Object, this._jwtServiceMock.Object); } #region Create @@ -47,11 +47,17 @@ namespace DevHive.Web.Tests }; Guid ratingId = Guid.NewGuid(); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createRatingServiceModel); - this.RatingServiceMock.Setup(p => p.RatePost(It.IsAny())).Returns(Task.FromResult(ratingId)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createRatingServiceModel); + this._ratingServiceMock + .Setup(p => p.RatePost(It.IsAny())) + .ReturnsAsync(ratingId); - IActionResult result = this.RatingController.RatePost(Guid.Empty, createRatingWebModel, String.Empty).Result; + IActionResult result = this._ratingController.RatePost(Guid.Empty, createRatingWebModel, String.Empty).Result; Assert.IsInstanceOf(result); @@ -82,11 +88,17 @@ namespace DevHive.Web.Tests }; Guid ratingId = Guid.NewGuid(); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createRatingServiceModel); - this.RatingServiceMock.Setup(p => p.RatePost(It.IsAny())).Returns(Task.FromResult(Guid.Empty)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(createRatingServiceModel); + this._ratingServiceMock + .Setup(p => p.RatePost(It.IsAny())) + .ReturnsAsync(Guid.Empty); - IActionResult result = this.RatingController.RatePost(Guid.Empty, createRatingWebModel, String.Empty).Result; + IActionResult result = this._ratingController.RatePost(Guid.Empty, createRatingWebModel, String.Empty).Result; Assert.IsInstanceOf(result); } @@ -114,10 +126,14 @@ namespace DevHive.Web.Tests IsLike = true }; - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingServiceModel); - this.RatingServiceMock.Setup(p => p.GetRatingById(It.IsAny())).Returns(Task.FromResult(readRatingServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readRatingServiceModel); + this._ratingServiceMock + .Setup(p => p.GetRatingById(It.IsAny())) + .ReturnsAsync(readRatingServiceModel); - IActionResult result = this.RatingController.GetRatingById(id).Result; + IActionResult result = this._ratingController.GetRatingById(id).Result; Assert.IsInstanceOf(result); } @@ -143,10 +159,14 @@ namespace DevHive.Web.Tests IsLike = true }; - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingServiceModel); - this.RatingServiceMock.Setup(p => p.GetRatingByPostAndUser(It.IsAny(), It.IsAny())).Returns(Task.FromResult(readRatingServiceModel)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readRatingServiceModel); + this._ratingServiceMock + .Setup(p => p.GetRatingByPostAndUser(It.IsAny(), It.IsAny())) + .ReturnsAsync(readRatingServiceModel); - IActionResult result = this.RatingController.GetRatingByUserAndPost(userId, postId).Result; + IActionResult result = this._ratingController.GetRatingByUserAndPost(userId, postId).Result; Assert.IsInstanceOf(result); } @@ -186,12 +206,20 @@ namespace DevHive.Web.Tests IsLike = true }; - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRatingServiceModel); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(readRatingWebModel); - this.RatingServiceMock.Setup(p => p.UpdateRating(It.IsAny())).Returns(Task.FromResult(readRatingServiceModel)); - - IActionResult result = this.RatingController.UpdateRating(userId, postId, updateRatingWebModel, String.Empty).Result; + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateRatingServiceModel); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readRatingWebModel); + this._ratingServiceMock + .Setup(p => p.UpdateRating(It.IsAny())) + .ReturnsAsync(readRatingServiceModel); + + IActionResult result = this._ratingController.UpdateRating(userId, postId, updateRatingWebModel, String.Empty).Result; Assert.IsInstanceOf(result); } @@ -210,11 +238,17 @@ namespace DevHive.Web.Tests IsLike = true }; - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(updateRatingServiceModel); - this.RatingServiceMock.Setup(p => p.UpdateRating(It.IsAny())).Returns(Task.FromResult(null)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(updateRatingServiceModel); + this._ratingServiceMock + .Setup(p => p.UpdateRating(It.IsAny())) + .Returns(Task.FromResult(null)); - IActionResult result = this.RatingController.UpdateRating(Guid.Empty, Guid.Empty, updateRatingWebModel, String.Empty).Result; + IActionResult result = this._ratingController.UpdateRating(Guid.Empty, Guid.Empty, updateRatingWebModel, String.Empty).Result; Assert.IsInstanceOf(result); } @@ -226,10 +260,14 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.RatingServiceMock.Setup(p => p.DeleteRating(It.IsAny())).Returns(Task.FromResult(true)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._ratingServiceMock + .Setup(p => p.DeleteRating(It.IsAny())) + .ReturnsAsync(true); - IActionResult result = this.RatingController.DeleteRating(Guid.Empty, Guid.Empty, String.Empty).Result; + IActionResult result = this._ratingController.DeleteRating(Guid.Empty, Guid.Empty, String.Empty).Result; Assert.IsInstanceOf(result); } @@ -240,10 +278,14 @@ namespace DevHive.Web.Tests string message = "Could not delete Rating"; Guid id = Guid.NewGuid(); - this.JwtServiceMock.Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())).Returns(true); - this.RatingServiceMock.Setup(p => p.DeleteRating(It.IsAny())).Returns(Task.FromResult(false)); + this._jwtServiceMock + .Setup(p => p.ValidateToken(It.IsAny(), It.IsAny())) + .Returns(true); + this._ratingServiceMock + .Setup(p => p.DeleteRating(It.IsAny())) + .ReturnsAsync(false); - IActionResult result = this.RatingController.DeleteRating(Guid.Empty, Guid.Empty, String.Empty).Result; + IActionResult result = this._ratingController.DeleteRating(Guid.Empty, Guid.Empty, String.Empty).Result; Assert.IsInstanceOf(result); -- cgit v1.2.3