public async Task AddReview_WhenInvalid_ShouldReturnView() { var controller = new HotelsController(hotelServiceMock.Object, imageServiceMock.Object, thumbnailServiceMock.Object, propertyServiceMock.Object); controller.ModelState.AddModelError("Rating", "Required"); var hotelId = 1; var review = new Review(); var result = await controller.AddReview(hotelId, review); Assert.IsType <ViewResult>(result); }
public async Task AddReview_WhenValid_ShouldCallServiceAndRedirect() { var controllerContext = ControllerContextProvider.GetDefault(); var controller = new HotelsController(hotelServiceMock.Object, imageServiceMock.Object, thumbnailServiceMock.Object, propertyServiceMock.Object) { ControllerContext = controllerContext }; var hotelId = 1; var review = new Review(); var result = await controller.AddReview(hotelId, review); var redirectResult = Assert.IsType <RedirectToActionResult>(result); int resultHotelId = (int)redirectResult.RouteValues["id"]; Assert.Null(redirectResult.ControllerName); Assert.Equal(nameof(controller.Hotel), redirectResult.ActionName); Assert.Equal(hotelId, resultHotelId); Assert.Equal(controllerContext.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier), review.ApplicationUserId); hotelServiceMock.Verify(s => s.AddReviewAsync(review), Times.Once); }