public RedirectToRouteResult RemoveFromCart(Cart cart, int productID, string returnUrl) { Product product = productsRepository.Products .FirstOrDefault(p => p.ProductID == productID); cart.RemoveLine(product); return RedirectToAction("Index", new { returnUrl }); }
public void Can_Remove_Item() { Cart cart = new Cart(); Product p1 = new Product() { ProductID = 1, Price = 5 }; Product p2 = new Product() { ProductID = 2, Price = 15 }; cart.AddItem(p1, 15); cart.AddItem(p2, 7); cart.RemoveLine(p1); Assert.AreEqual(1, cart.Lines.Count); Assert.AreEqual(2, cart.Lines[0].Product.ProductID); Assert.AreEqual(7, cart.Lines[0].Quantity); }