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.Web.Tests/RatingController.Tests.cs | 118 ++++++++++++++------- 1 file changed, 80 insertions(+), 38 deletions(-) (limited to 'src/Web/DevHive.Web.Tests') 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