public void CanCreateRevisitedCartWithExistingItems()
        {
            var cart = RevisitedCart.CreateWithItems(1, new List <CartItem> {
                CartItem.Create(1, 1, 9.99m, 1)
            });

            Assert.AreEqual(1, cart.CartItems.Count());
            Assert.AreEqual(9.99m, cart.CartItems.Single().CurrentPrice);
        }
        public RevisitedCart RetrieveCart(int cartId)
        {
            var cart = _context.Carts.AsNoTracking().Where(c => c.CartId == cartId).
                       Select(c => new { c.CartId, c.CartItems }).SingleOrDefault();

            if (cart != null)
            {
                return(RevisitedCart.CreateWithItems(cart.CartId, cart.CartItems));
            }
            return(RevisitedCart.Create(cartId));
        }
        public RevisitedCart StoreCartWithInitialProduct(NewCart newCart)
        {
            if (newCart.CartItems.Count != 1)
            {
                return(null);
            }
            CheckForExistingCustomer(newCart);
            _context.Carts.Add(newCart);
            _context.SaveChanges();
            var cart = RevisitedCart.CreateWithItems(newCart.CartId, newCart.CartItems);

            cart.SetCookieData(newCart.CartCookie, newCart.Expires);
            return(cart);
        }