public ActionResult Create(TruckViewModel truckViewModel) { try { if (ModelState.IsValid) { TruckService.Add(truckViewModel); return(RedirectToAction(nameof(Index))); } return(View(truckViewModel)); } catch (Exception ex) { Logger.LogError(ex, ex.Message); return(View(truckViewModel)); } }
public void Add_ShouldAddNewItem( string chassis, EnumModelViewModel model, int year, int modelYear) { // Arrange var truckViewModel = new TruckViewModel { Chassis = chassis, Model = model, Year = year, ModelYear = modelYear }; // Act TruckService.Add(truckViewModel); var truck = FakeUnitOfWork.TruckRepository.GetAll(t => t.Chassis.Equals(chassis)).FirstOrDefault(); // Assert Assert.AreEqual(chassis, truck.Chassis, "Item was not added"); }