public void Can_Remove_Line() { // Arrange - create some test products PRODUCT p1 = new PRODUCT { ProductId = 1, Name = "P1" }; PRODUCT p2 = new PRODUCT { ProductId = 2, Name = "P2" }; PRODUCT p3 = new PRODUCT { ProductId = 3, Name = "P3" }; // Arrange - create a new cart CART target = new CART(); // Arrange - add some products to the cart target.AddItem(p1, 1); target.AddItem(p2, 3); target.AddItem(p3, 5); target.AddItem(p2, 1); // Act target.RemoveLine(p2); // Assert Assert.AreEqual(target.Lines.Where(c => c.Product == p1).Count(), 1); Assert.AreEqual(target.Lines.Where(c => c.Product == p2).Count(), 0); Assert.AreEqual(target.Lines.Where(c => c.Product == p3).Count(), 1); Assert.AreEqual(target.Lines.Count(), 2); }
public RedirectToRouteResult RemLineFromCart(CART cart, int productId, string returnUrl) { PRODUCT product = repository.Products.FirstOrDefault(p => p.ProductId == productId); if (product != null) { cart.RemoveLine(product); //GetCart().RemoveLine(product); } return(RedirectToAction("Index", new { returnUrl })); }