public void ReturnBadRequest_WhenRatingDoesNotExist_OnCallToUpdateRating() { var updatedRating = new Rating { Id = 1, UserId = 1, Description = "Test", Code = "Test" }; var userHelper = A.Fake <IUserHelper>(); A.CallTo(() => userHelper.MatchingUsers(A <HttpContext> .Ignored, updatedRating.UserId)).Returns(true); var ratingRepository = A.Fake <IRatingRepository>(); A.CallTo(() => ratingRepository.RatingExists(updatedRating.Id)).Returns(false); var validator = new RatingValidator(); var controller = new RatingsController(ratingRepository, null, userHelper, validator); var response = controller.UpdateRating(updatedRating); Assert.AreEqual((int)HttpStatusCode.BadRequest, ((BadRequestObjectResult)response.Result).StatusCode); Assert.AreEqual($"Rating with Id {updatedRating.Id} does not exist.", ((BadRequestObjectResult)response.Result).Value); }
public void ReturnRating_WhenValidUser_CallsUpdateRating() { var updatedRating = new Rating { Id = 1, UserId = 1, Description = "Test", Code = "Test" }; var result = new Rating { Id = updatedRating.Id }; var userHelper = A.Fake <IUserHelper>(); A.CallTo(() => userHelper.MatchingUsers(A <HttpContext> .Ignored, updatedRating.UserId)).Returns(true); var ratingRepository = A.Fake <IRatingRepository>(); A.CallTo(() => ratingRepository.RatingExists(updatedRating.Id)).Returns(true); A.CallTo(() => ratingRepository.GetRating(updatedRating.Id)).Returns(result); var validator = new RatingValidator(); var controller = new RatingsController(ratingRepository, null, userHelper, validator); var response = controller.UpdateRating(updatedRating); A.CallTo(() => ratingRepository.Update(updatedRating)).MustHaveHappened(); Assert.AreEqual(result.Id, response.Value.Id); }
public void ReturnUnauthorized_WhenInvalidUser_CallsUpdateRating() { var updatedRating = new Rating { Id = 1, UserId = 1, Description = "Test", Code = "Test" }; var userHelper = A.Fake <IUserHelper>(); A.CallTo(() => userHelper.MatchingUsers(A <HttpContext> .Ignored, updatedRating.UserId)).Returns(false); var validator = new RatingValidator(); var controller = new RatingsController(null, null, userHelper, validator); var response = controller.UpdateRating(updatedRating); Assert.AreEqual((int)HttpStatusCode.Unauthorized, ((UnauthorizedResult)response.Result).StatusCode); }