예제 #1
0
 public void Cart_Item_Quantity_Should_Adjust_To_10()
 {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     cart.AddItem(p);
     cart.AdjustQuantity(p, 10);
     Assert.AreEqual(10, cart.TotalItems);
 }
예제 #2
0
 public void Cart_Can_Return_Item_By_SKU()
 {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     cart.AddItem(p, 1);
     var item = cart.FindItem("SKU");
     Assert.IsNotNull(item);
 }
예제 #3
0
 public void Cart_Returns_Null_When_No_Sku_Found()
 {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     cart.AddItem(p, 1);
     var item = cart.FindItem("SKU1");
     Assert.IsNull(item);
 }
예제 #4
0
 public Customer(string userName, string email, string first, string last, ShoppingCart cart)
     : base(userName)
 {
     FirstName = first;
     LastName = last;
     Email = email;
     LanguageCode = "en";
     Cart = cart ?? new ShoppingCart();
     UserName = userName ?? Guid.NewGuid().ToString();
 }
예제 #5
0
        public void ItemLastAdded_Should_Be_Sku2_When_SKu1_Sku2_Added_In_Sequence()
        {
            ShoppingCart cart = new ShoppingCart("TEST");
            Product p = new Product("SKU1");
            Product p2 = new Product("SKU2");
            cart.AddItem(p, 1, DateTime.Now.AddSeconds(-1));
            cart.AddItem(p2, 1, DateTime.Now.AddSeconds(1));

            Assert.AreEqual("SKU2", cart.ItemLastAdded.Product.SKU);
        }
 public IList<ShippingMethod> CalculateShipping(ShoppingCart cart)
 {
     //pull the rates
     var shippingMethods=OrderRepository.GetShippingMethods().ToList();
     //get the total weight of the order
     decimal totalWeight = cart.Items.Sum(x => x.Product.WeightInPounds * x.Quantity);
     //loop the methods and set the cost
     shippingMethods.ForEach(x => x.Cost = x.BaseRate + (x.RatePerPound * totalWeight));
     return shippingMethods;
 }
예제 #7
0
        public decimal CalculateTax(ShoppingCart cart)
        {
            Dictionary<string, decimal> TaxTable = new Dictionary<string, decimal>();
            TaxTable.Add("HI", .0512M);
            TaxTable.Add("CA", .0815M);
            TaxTable.Add("WA", .0612M);

            decimal result = 0;
            decimal rate = 0;
            //check the rates against the shipping address
            if(TaxTable.ContainsKey(cart.ShippingAddress.StateOrProvince))
                rate = TaxTable[cart.ShippingAddress.StateOrProvince];

            result = rate * cart.SubTotal;

            return result;
        }
예제 #8
0
 public void Items_Count_Should_Be_1_When_2_of_Same_Product_Added()
 {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     cart.AddItem(p);
     cart.AddItem(p);
     Assert.AreEqual(1, cart.Items.Count);
 }
예제 #9
0
        public void SaveCart(ShoppingCart cart)
        {
            //using the Orders/OrderItems tables to persist the car
            //with the idea that a cart is an order that hasn't checked out
            //yet. This is a DB-centric decision, our model separates this
            //concept. StatusID 99 marks an order as "Not Checked Out"
            List<DbCommand> commands = new List<DbCommand>();
            Guid orderID = Guid.NewGuid();

            orderID = GetCartID(cart.UserName);

            var settings = new Dictionary<string, object>();

            if (cart.BillingAddress != null)
                settings.Add(OrdersTable.Columns.BillingAddressID, cart.BillingAddress.AddressID);

            if (cart.ShippingAddress != null)
                settings.Add(OrdersTable.Columns.ShippingAddressID, cart.ShippingAddress.AddressID);

            settings.Add(OrdersTable.Columns.ShippingService, cart.ShippingService);
            settings.Add(OrdersTable.Columns.ShippingAmount, cart.ShippingAmount);
            settings.Add(OrdersTable.Columns.TaxAmount, cart.TaxAmount);

            //save down any address (billing/shipping), selected shipping, and tax info
            var sql = OrdersTable.Update(settings)
                .Where(OrdersTable.Columns.OrderID, orderID);

            commands.Add(sql.BuildCommand());

            //remove the existing items
            commands.Add(OrderItemsTable.Delete().Where(OrderItemsTable.Columns.OrderID, orderID).BuildCommand());

            //save each item in the cart
            foreach (var item in cart.Items) {
                var itemSql = OrderItemsTable.Insert(new Dictionary<string, object>()
                {
                    {OrderItemsTable.Columns.SKU,item.Product.SKU},
                    {OrderItemsTable.Columns.OrderID,orderID},
                    {OrderItemsTable.Columns.Quantity,item.Quantity},
                    {OrderItemsTable.Columns.DateAdded,item.DateAdded},
                    {OrderItemsTable.Columns.Discount,item.Discount},
                    {OrderItemsTable.Columns.DiscountReason,item.DiscountReason}

                });
                commands.Add(itemSql.BuildCommand());
            }

            //all in one, nice transaction BOOYAH!
            SqlHelper.Execute(commands, connectionStringName);
        }
예제 #10
0
 void AddCartItemsToOrder(ShoppingCart cart)
 {
     foreach (ShoppingCartItem item in cart.Items) {
         AddLineItem(item);
     }
 }
예제 #11
0
 public void Items_Count_Should_Be_0_When_10_Items_Adjusted_To_Negative_10()
 {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     cart.AddItem(p, 10);
     cart.AdjustQuantity(p, -10);
     Assert.AreEqual(0, cart.Items.Count);
 }
예제 #12
0
 public void Total_Should_Be_2_When_2_Different_Products_Added()
 {
     ShoppingCart cart = new ShoppingCart("TEST");
     cart.AddItem(new Product("SKU1"));
     cart.AddItem(new Product("SKU2"));
     Assert.AreEqual(2, cart.TotalItems);
 }
예제 #13
0
 public void Total_Should_Be_1_When_1_Product_Added()
 {
     ShoppingCart cart = new ShoppingCart("TEST");
     cart.AddItem(new Product("SKU"));
     Assert.AreEqual(1, cart.TotalItems);
 }
예제 #14
0
        public void Total_Should_Be_110_With_90_Subtotal_10_Tax_and_10_Shipping()
        {
            ShoppingCart cart = new ShoppingCart("TEST");
            Product p = new Product("SKU");
            p.Price = 90;
            cart.AddItem(p, 1);
            Assert.AreEqual(90, cart.SubTotal);

            cart.TaxAmount = 10;
            cart.ShippingAmount = 10;

            Assert.AreEqual(110, cart.Total);
        }
예제 #15
0
 public void Nothing_Should_Be_Added_When_0_Passed_as_Quantity_To_AddItem()
 {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     cart.AddItem(p, 0);
     Assert.AreEqual(0, cart.Items.Count);
 }
예제 #16
0
        public void Items_Count_Should_Be_0_When_SKU_Removed()
        {
            ShoppingCart cart = new ShoppingCart("TEST");
            Product p = new Product("SKU");
            cart.AddItem(p, 1);
            Assert.AreEqual(1, cart.Items.Count);

            cart.RemoveItem("SKU");
            Assert.AreEqual(0, cart.Items.Count);
        }
예제 #17
0
        public void Items_Count_Should_Be_0_When_2_Items_Cleared()
        {
            ShoppingCart cart = new ShoppingCart("TEST");
            Product p = new Product("SKU");
            Product p2 = new Product("SKU2");
            //Clock-foolery
            cart.AddItem(p, 1);
            cart.AddItem(p2, 1);
            Assert.AreEqual(2, cart.Items.Count);

            cart.ClearItems();
            Assert.AreEqual(0, cart.Items.Count);
        }