public void ReturnGetUserRatings_WhenUserExists_OnCallToGetCurrentUserRatings() { var userId = 1; var ratingRepository = A.Fake <IRatingRepository>(); var userHelper = A.Fake <IUserHelper>(); A.CallTo(() => userHelper.GetUserId(A <HttpContext> .Ignored)).Returns(userId); var userRepository = A.Fake <IUserRepository>(); A.CallTo(() => userRepository.UserExists(userId)).Returns(true); var controller = new RatingsController(ratingRepository, userRepository, userHelper, null); var response = controller.GetCurrentUserRatings(); A.CallTo(() => ratingRepository.GetUserRatings(userId)).MustHaveHappened(); }
public void ReturnBadRequest_WhenUserDoesNotExist_OnCallToGetCurrentUserRatings() { var userId = 1; var ratingRepository = A.Fake <IRatingRepository>(); var userHelper = A.Fake <IUserHelper>(); A.CallTo(() => userHelper.GetUserId(A <HttpContext> .Ignored)).Returns(userId); var userRepository = A.Fake <IUserRepository>(); A.CallTo(() => userRepository.UserExists(userId)).Returns(false); var controller = new RatingsController(ratingRepository, userRepository, userHelper, null); var response = controller.GetCurrentUserRatings(); Assert.AreEqual((int)HttpStatusCode.BadRequest, ((BadRequestObjectResult)response.Result).StatusCode); Assert.AreEqual($"User with Id {userId} does not exist.", ((BadRequestObjectResult)response.Result).Value); }