public void AddCarReturnsViewResultWithCarModel() { var mock = new Mock <ICarRepository>(); var controller = new CarController(mock.Object); controller.ModelState.AddModelError("Name", "Required"); Car newCar = new Car(); var result = controller.AddCar(newCar); var viewResult = Xunit.Assert.IsType <ViewResult>(result); Xunit.Assert.Equal(newCar, viewResult?.Model); }
public void AddCarReturnsARedirectAndAddsCar() { var mock = new Mock <ICarRepository>(); var controller = new CarController(mock.Object); var newUser = new Car() { Type = "Jaguar", Year = 2019 }; var result = controller.AddCar(newUser); var redirectToActionResult = Xunit.Assert.IsType <RedirectToActionResult>(result); Xunit.Assert.Null(redirectToActionResult.ControllerName); Xunit.Assert.Equal("Index", redirectToActionResult.ActionName); mock.Verify(r => r.Create(newUser)); }
public async Task <OkResult> CreateCar(Car car) { await _carController.AddCar(car); return(Ok()); }
public void AddCar() { ViewResult result = controller.AddCar(carModel.Object) as ViewResult; Assert.IsNull(result); }