Esempio n. 1
0
 public RedirectToRouteResult RemoveFromCart(Cart cart, int productId, string returnUrl)
 {
     Product product = repository.Products.FirstOrDefault(p => p.ProductID == productId);
     if (product != null)
     {
         cart.RemoveLine(product);
     }
     return RedirectToAction("Index", new { returnUrl });
 }
Esempio n. 2
0
        public void Can_Remove_Line()
        {
            // Arrange - Create some test games
            Game p1 = new Game { GameID = 1, Name = "P1" };
            Game p2 = new Game { GameID = 2, Name = "P2" };
            Game p3 = new Game { GameID = 3, Name = "P3" };

            // Arrange - Create a new cart
            Cart target = new Cart();
            // Arrange - add some games 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.Game == p2).Count(), 0);
            Assert.AreEqual(target.Lines.Count(), 2);
        }
Esempio n. 3
0
 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 == p2).Count(), 0);
     Assert.AreEqual(target.Lines.Count(), 2);
 }