public void CanAddANewLine()
        {
            //Arrange
            Pizza p1 = new Pizza { PizzaId = 1, Name = "Pizza1" };
            Pizza p2 = new Pizza { PizzaId = 2, Name = "Pizza2" };
            Cart cart = new Cart();

            //Action
            cart.AddItem(p1, 1);
            cart.AddItem(p2, 1);
            CartLine[] results = cart.Lines.ToArray();

            //Assert
            Assert.AreEqual(results.Length, 2);
            Assert.AreEqual(results[1].Pizza, p2);
        }
        public void CanAddQuantityToExistingLine()
        {
            //Arrange
            Pizza p1 = new Pizza { PizzaId = 1, Name = "Pizza1" };
            Pizza p2 = new Pizza { PizzaId = 2, Name = "Pizza2" };
            Cart cart = new Cart();

            //Action
            cart.AddItem(p1, 1);
            cart.AddItem(p2, 1);
            cart.AddItem(p1, 5);
            CartLine[] results = cart.Lines.OrderBy(p => p.Pizza.PizzaId).ToArray();

            //Assert
            Assert.AreEqual(results.Length, 2);
            Assert.AreEqual(results[0].Quantity, 6);
            Assert.AreEqual(results[1].Quantity, 1);
        }
        public void CanRemoveLine()
        {
            //Arrange
            Pizza p1 = new Pizza { PizzaId = 1, Name = "Pizza1" };
            Pizza p2 = new Pizza { PizzaId = 2, Name = "Pizza2" };
            Pizza p3 = new Pizza { PizzaId = 3, Name = "Pizza3" };
            Cart cart = new Cart();

            //Action
            cart.AddItem(p1, 1);
            cart.AddItem(p2, 2);
            cart.AddItem(p1, 5);
            cart.AddItem(p3, 3);
            cart.RemoveLine(p1);

            //Assert
            Assert.AreEqual(cart.Lines.Count(), 2);
            Assert.AreEqual(cart.Lines.Where(p => p.Pizza == p1).Count(), 0);
        }
        public RedirectToRouteResult AddToCart(Cart cart, int PizzaId, string returnUrl)
        {
            Pizza pizza = repository.Pizzas.FirstOrDefault(p => p.PizzaId == PizzaId);

            if (pizza != null)
            {
                if (pizza.Name == "Create Your Own")
                {
                    foreach (var topping in Session["ToppingList"] as List<Topping>)
                    {
                        pizza.Price += topping.Price;
                    }
                    cart.AddItem(pizza, 1);
                }
                else
                {
                    cart.AddItem(pizza, 1);
                }
                
            }
            return RedirectToAction("Index", new { returnUrl });
        }
        public ActionResult RetrieveSavedOrder(Cart cart)
        {
            var orderlineQuery = orderlineRepository.Orderlines.Where(u => u.UserId == WebSecurity.CurrentUserId).ToList();
            cart.Clear();
            foreach (var orderline in orderlineQuery)
            {
                if (orderline != null)
                {
                    if (orderline.OrderId == 0)
                    {
                        Pizza pizza = new Pizza();
                        pizza.PizzaId = orderline.PizzaId;
                        pizza.Name = repository.Pizzas.FirstOrDefault(p => p.PizzaId == pizza.PizzaId).Name;
                        pizza.Size = repository.Pizzas.FirstOrDefault(p => p.PizzaId == pizza.PizzaId).Size;
                        pizza.Price = orderline.OrderlinePrice;
                        cart.AddItem(pizza, 1);
                        TempData["message"] = string.Format("Order Retrieved");
                    }
                }
            }

            if(orderlineQuery.Count() == 0){
                TempData["message"] = string.Format("No Items Saved");               
            }
            return RedirectToAction("Index");
        }
        public void CanClearCart()
        {
            //Arrange
            Pizza p1 = new Pizza { PizzaId = 1, Name = "Pizza1", Price = 5M };
            Pizza p2 = new Pizza { PizzaId = 2, Name = "Pizza2", Price = 3.50M };
            Pizza p3 = new Pizza { PizzaId = 3, Name = "Pizza3", Price = 51M };
            Cart cart = new Cart();

            //Action
            cart.AddItem(p1, 1);
            cart.AddItem(p2, 2);
            cart.AddItem(p3, 1);
            cart.Clear();

            //Assert
            Assert.AreEqual(cart.Lines.Count(), 0);
        }
        public void CalcCartTotal()
        {
            //Arrange
            Pizza p1 = new Pizza { PizzaId = 1, Name = "Pizza1", Price = 5M };
            Pizza p2 = new Pizza { PizzaId = 2, Name = "Pizza2", Price = 3.50M };
            Pizza p3 = new Pizza { PizzaId = 3, Name = "Pizza3", Price = 51M };
            Cart cart = new Cart();

            //Action
            cart.AddItem(p1, 1);
            cart.AddItem(p2, 2);
            cart.AddItem(p3, 1);
            decimal result = cart.GetTotalValue();

            //Assert
            Assert.AreEqual(result, 63M);
        }