public void When_Rating_Correct_Return_Ok(string rating) { var validator = new NewRatingValidator(); var result = validator.TestValidate(rating); result.ShouldNotHaveValidationErrorFor(rating => rating); }
public void When_Rating_Is_Wrong_Return_Error(string rating) { var validator = new NewRatingValidator(); var result = validator.TestValidate(rating); result.ShouldHaveValidationErrorFor(rating => rating); }
public async Task <IActionResult> AddRating() { var newRatingValidator = new NewRatingValidator(); var id = int.Parse(Request.Form["id"]); var validateResult = await newRatingValidator.ValidateAsync(Request.Form["newRating"]); var result = FilmDetailsVm.Map(await _filmsService.GetFIlmDetails(id)); if (!validateResult.IsValid) { foreach (var error in validateResult.Errors) { result.NewRatingErrors.Add(error.ErrorMessage); } return(View("Details", result)); } await _filmsService.AddNewRating(id, int.Parse(Request.Form["newRating"])); result.Ratings.Add(int.Parse(Request.Form["newRating"])); return(View("Details", result)); }