public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails) { if (cart.Lines.Count() == 0) { ModelState.AddModelError("", "Sorry, your cart is empty!"); } if (ModelState.IsValid) { orderProcessor.ProcessOrder(cart, shippingDetails); cart.Clear(); return View("Completed"); } else { return View(shippingDetails); } }
public void Can_Clear_Contents() { // Arrange Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100M }; Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50M }; Cart target = new Cart(); target.AddItem(p1, 1); target.AddItem(p2, 1); // Act target.Clear(); // Assert Assert.AreEqual(target.Lines.Count(), 0); }