private static ShoppingCart CreateNewShoppingCart(string shoppingCartId)
 {
     ShoppingCart shoppingCart;
     shoppingCart = new ShoppingCart(new List<ShoppingCartItem>())
                        {
                            ShoppingCartId = shoppingCartId,
                            Currency = "USD",
                            TaxRate = .09
                        };
     return shoppingCart;
 }
        public void Get_GetsShoppingCartForUser()
        {
            var shoppingCart = new ShoppingCart(new ObservableCollection<ShoppingCartItem>()) { FullPrice = 200, TotalDiscount = 100 };
            var shoppingCartRepository = new MockShoppingCartRepository();
            shoppingCartRepository.GetByIdDelegate = (userId) =>
                                         {
                                             return shoppingCart;
                                         };

            var target = new ShoppingCartController(shoppingCartRepository, new MockProductRepository());
            var result = target.Get("JohnDoe");
            Assert.AreEqual(result, shoppingCart);
        }
 private static void UpdatePrices(ShoppingCart shoppingCart)
 {
     double fullPrice = 0, discount = 0;
     foreach (var shoppingCartItem in shoppingCart.ShoppingCartItems)
     {
         fullPrice += shoppingCartItem.Product.ListPrice * shoppingCartItem.Quantity;
         discount += fullPrice * shoppingCartItem.Product.DiscountPercentage/100;
         shoppingCart.FullPrice = fullPrice;
         shoppingCart.TotalDiscount = discount;
         shoppingCart.TotalPrice = fullPrice - discount;
     }
 }
        public bool RemoveItemFromCart(ShoppingCart shoppingCart, string itemId)
        {
            lock (_lock)
            {
                if (shoppingCart == null)
                {
                    throw new ArgumentNullException("shoppingCart");
                }

                ShoppingCartItem item = shoppingCart.ShoppingCartItems.FirstOrDefault(i => i.Id == itemId);
                bool itemRemoved = shoppingCart.ShoppingCartItems.Remove(item);

                if (itemRemoved)
                {
                    UpdatePrices(shoppingCart);
                }

                return itemRemoved;
            }
        }
 bool IShoppingCartRepository.RemoveItemFromCart(ShoppingCart shoppingCart, string itemId)
 {
     return RemoveItemFromCartDelegate(shoppingCart, itemId);
 }