Example #1
0
 public RedirectToRouteResult RemoveFromCart(Cart cart, int ProductId, string returnUrl)
 {
     Product product = repository.Products.Where(m => m.ProductID == ProductId).FirstOrDefault();
     if (product != null)
     {
         cart.RemoveLine(product);
     }
     return RedirectToAction("Index", new { returnUrl });
 }
Example #2
0
        public void Cart_Can_Remove_Lines_And_Clear()
        {
            var productsArray = products.Products.ToArray();
            Cart target = new Cart();
            target.AddItem(productsArray[0], 1);
            target.AddItem(productsArray[1], 2);
            target.AddItem(productsArray[2], 2);
            target.RemoveLine(productsArray[0]);

            var result = target.Lines.ToArray();
            Assert.AreEqual(result.Count(), 2);
            Assert.AreEqual(result[0].Product, productsArray[1]);
            Assert.AreEqual(result[1].Product, productsArray[2]);

            target.Clear();
            result = target.Lines.ToArray();
            Assert.AreEqual(result.Count(), 0);
        }