public RedirectToRouteResult RemoweFromCart(Cart cart,int productId, string returnUrl) { Product product = repository.Products .FirstOrDefault(p => p.ProductID == productId); if (product!=null) { cart.RemoweLine(product); } return RedirectToAction("Index", new {returnUrl}); }
public void Can_Remove_Line() { //Arrange Product p1 = new Product {ProductID = 1, Name = "P1"}; Product p2 = new Product {ProductID = 2, Name = "P2"}; Product p3 = new Product {ProductID = 3, Name = "P3"}; Cart target = new Cart(); //Act target.AddItem(p1, 1); target.AddItem(p2, 3); target.AddItem(p3, 5); target.AddItem(p2, 1); target.RemoweLine(p2); //Assert Assert.AreEqual(target.Lines.Where(p => p.Product == p2).Count(), 0); Assert.AreEqual(target.Lines.Count(), 2); }