public RedirectToRouteResult RemoveFromCart(Cart cart, int PizzaId, string returnUrl) { Pizza pizza = repository.Pizzas.FirstOrDefault(p => p.PizzaId == PizzaId); if (pizza != null) { cart.RemoveLine(pizza); } return RedirectToAction("Index", new { returnUrl }); }
public void CanRemoveLine() { //Arrange Pizza p1 = new Pizza { PizzaId = 1, Name = "Pizza1" }; Pizza p2 = new Pizza { PizzaId = 2, Name = "Pizza2" }; Pizza p3 = new Pizza { PizzaId = 3, Name = "Pizza3" }; Cart cart = new Cart(); //Action cart.AddItem(p1, 1); cart.AddItem(p2, 2); cart.AddItem(p1, 5); cart.AddItem(p3, 3); cart.RemoveLine(p1); //Assert Assert.AreEqual(cart.Lines.Count(), 2); Assert.AreEqual(cart.Lines.Where(p => p.Pizza == p1).Count(), 0); }