public void TestItAll() { List <Car> cars = _manager.GetAll(); Assert.AreEqual(3, cars.Count); cars = _manager.GetAll(vendor: "V"); Assert.AreEqual(1, cars.Count); cars = _manager.GetAll(minPrice: 20); Assert.AreEqual(2, cars.Count); cars = _manager.GetAll(minPrice: 21); Assert.AreEqual(1, cars.Count); cars = _manager.GetAll(maxPrice: 20); Assert.AreEqual(2, cars.Count); cars = _manager.GetAll(maxPrice: 18); Assert.AreEqual(1, cars.Count); Car car = _manager.GetById(1); Assert.AreEqual(1, car.Id); Assert.IsNull(_manager.GetById(100)); int howMany = _manager.GetAll().Count; Car newCar = new Car { Make = "WV", Model = "Polo", Price = 25 }; Car c = _manager.Add(newCar); Assert.AreEqual(howMany + 1, _manager.GetAll().Count); Car updatedCar = _manager.Update(c.Id, new Car() { Make = "WV", Model = "Polo", Price = 26 }); Assert.AreEqual(26, updatedCar.Price); Assert.IsNull(_manager.Update(100, null)); howMany = _manager.GetAll().Count; Car deletedCar = _manager.Delete(1); Assert.AreEqual(1, deletedCar.Id); Assert.IsNull(_manager.Delete(100)); }
public ActionResult <Car> Delete(int id) { Car deletedCar = _manager.Delete(id); if (deletedCar == null) { return(NotFound(id)); } return(Ok(deletedCar)); }
// GET: Cars/Delete/5 public ActionResult DeleteCar(int id) { var carToDelete = carsmanager.GetByID(id); if (carsmanager.Delete(carToDelete)) { return(RedirectToAction("CartypsAndCar")); } else { return(View("Error")); } }