public void TestBookingFormSuccessfulPost() { BookingController controller = GetController(true); var formModel = new BookingFormViewModel() { AccommodationId = 1, AccommodationName = "Test Accommodation", Persons = new List <BookingPerson>() { new BookingPerson() { Country = new Country() { Id = 1 }, Nationality = new Country() { Id = 2 } } } }; RedirectToActionResult result = controller.BookingForm(formModel) as RedirectToActionResult; Assert.Equal("InsuranceForm", result.ActionName); }
public void TestBookingFormPostNonExistentAccommodation() { BookingController controller = GetController(false); //Fake post data with a non-existent accommodation var formModel = new BookingFormViewModel() { AccommodationId = 333, AccommodationName = "Test Accommodation", Persons = new List <BookingPerson>() { new BookingPerson() { Country = new Country() { Id = 1 }, Nationality = new Country() { Id = 2 } } } }; IActionResult result = controller.BookingForm(formModel); Assert.IsType <BadRequestResult>(result); }
public void TestBookingFormBadPost() { BookingController controller = GetController(true); //Fake post data with missing attributes var formModel = new BookingFormViewModel() { AccommodationId = 1, AccommodationName = "Test Accommodation", Persons = new List <BookingPerson>() { new BookingPerson() { Country = new Country() { Id = 1 }, Nationality = new Country() { Id = 2 } } } }; //Manually add error to model state controller.ModelState.AddModelError("test", "Test Error"); ViewResult result = controller.BookingForm(formModel) as ViewResult; Assert.Equal("BookingForm", result.ViewName); Assert.False(controller.ModelState.IsValid); }
public void TestBookingFormBadRequest() { //Initialize controller and excute action. //No accommodations are in the repository. BookingController controller = GetController(false); IActionResult result = controller.BookingForm(1, null); //Test if controller returned a NotFoundResult. Assert.IsType <NotFoundResult>(result); }
public void BookingFormTest() { var controller = new BookingController(srv); var result = controller.BookingForm(1) as ViewResult; var bf = (BookingFormViewModel)result.ViewData.Model; Assert.AreEqual("BookingForm", result.ViewName); Assert.IsNotNull(bf); Assert.IsNotNull(bf.Poster); Assert.AreEqual(1, bf.Poster.MovieId); Assert.AreEqual(1, bf.Poster.HallId); Assert.AreEqual(55.0, bf.Poster.BasePrice); }
public void TestBookingFormSuccessfulGet() { //Initialize controller and execute action //There are accommodations in the repository. BookingController controller = GetController(true); ViewResult result = controller.BookingForm(1, null) as ViewResult; BookingFormViewModel model = result.Model as BookingFormViewModel; Assert.Equal("BookingForm", result.ViewName); Assert.Equal(4, model.Persons.Count); }