public async Task vistaDatosReservaPost_ModelIsValid() { // Arrange using (context) { /////// var controller = new ReservasController(context); DatosHabitacionReservaViewModel expectedModel = new DatosHabitacionReservaViewModel { idPersona = 2, nombre = "Prueba2", apellidos = "Prueba2 Prueba2", nif = "87654321B", comentarios = "patata", fechaFin = new DateTime(2016, 12, 27), fechaInicio = new DateTime(2016, 12, 25), regimenComida = 1 }; // Act var result = await controller.vistaDatosReservaPost(new DatosReservaViewModel { idPersona = 2, nombre = "Prueba2", apellidos = "Prueba2 Prueba2", nif = "87654321B", comentarios = "patata", fechaFin = new DateTime(2016, 12, 27), fechaInicio = new DateTime(2016, 12, 25), regimenComida = 1 }); //Assert var viewResult = Assert.IsType <RedirectToActionResult>(result); viewResult.ActionName = "vistaSeleccionHabitacionReserva"; DatosHabitacionReservaViewModel resultado = new DatosHabitacionReservaViewModel { idPersona = (int)(result as RedirectToActionResult).RouteValues["idPersona"], nombre = (String)(result as RedirectToActionResult).RouteValues["nombre"], apellidos = (String)(result as RedirectToActionResult).RouteValues["apellidos"], nif = (String)(result as RedirectToActionResult).RouteValues["nif"], fechaInicio = (DateTime)(result as RedirectToActionResult).RouteValues["fechaInicio"], fechaFin = (DateTime)(result as RedirectToActionResult).RouteValues["fechaFin"], comentarios = (String)(result as RedirectToActionResult).RouteValues["comentarios"], regimenComida = (int)(result as RedirectToActionResult).RouteValues["regimenComida"] }; Assert.Equal(expectedModel, resultado, Comparer.Get <DatosHabitacionReservaViewModel>((p1, p2) => p1.idPersona == p2.idPersona && p1.nif == p2.nif && p1.comentarios == p2.comentarios && p1.fechaFin == p2.fechaFin && p1.fechaInicio == p2.fechaInicio && p1.regimenComida == p2.regimenComida)); } }
public async Task vistaDatosReservaPost_ModelIsValid_NotRooms() { // Arrange using (context) { var controller = new ReservasController(context); DatosReservaViewModel expectedModel = new DatosReservaViewModel { idPersona = 2 }; // Act var result = await controller.vistaDatosReservaPost(new DatosReservaViewModel { idPersona = 2, nombre = "Prueba2", apellidos = "Prueba2 Prueba2", nif = "87654321B", comentarios = "patata", fechaFin = new DateTime(2018, 01, 20), fechaInicio = new DateTime(2018, 01, 10), regimenComida = 1 }); //Assert var viewResult = Assert.IsType <ViewResult>(result); DatosReservaViewModel model = (result as ViewResult).Model as DatosReservaViewModel; Assert.Equal(expectedModel, model, Comparer.Get <DatosReservaViewModel>((p1, p2) => p1.idPersona == p2.idPersona)); } }
public async Task vistaDatosReservaPost_ModelIsNotValid() { // Arrange using (context) { var controller = new ReservasController(context); controller.ModelState.AddModelError("fechaInicio", "Required"); DatosReservaViewModel expectedModel = new DatosReservaViewModel { idPersona = 2 }; // Act var result = await controller.vistaDatosReservaPost(new DatosReservaViewModel { idPersona = 2 }); //Assert var viewResult = Assert.IsType <ViewResult>(result); DatosReservaViewModel model = (result as ViewResult).Model as DatosReservaViewModel; Assert.Equal(expectedModel, model, Comparer.Get <DatosReservaViewModel>((p1, p2) => p1.idPersona == p2.idPersona)); } }