Ejemplo n.º 1
0
 public void Total_Should_Be_2_When_2_Same_Products_Added() {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     cart.AddItem(p);
     cart.AddItem(p);
     Assert.Equal(2, cart.TotalItems);
 }
Ejemplo n.º 2
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.Equal(10, cart.TotalItems);
 }
Ejemplo n.º 3
0
        public void LoadCart() {
            this.Cart = new ShoppingCart(this.UserName);

           
            //load up the cart
            //a cart is just an Order, marked with "NotCheckedOut"
            //the following factory method will retrieve the current Order
            //or create a new one
            var existingOrder = Order.FindCurrentOrCreateNew(this.UserName);
            
            if (existingOrder != null) {
                //get the items
                //pull the products first
                var skus = from items in existingOrder.OrderItems
                           select items.SKU;

                var products = from p in Product.All()
                               join o in OrderItem.All() on p.SKU equals o.SKU
                               where o.OrderID==existingOrder.OrderID
                               select p;

                foreach (var item in existingOrder.OrderItems) {
                    this.Cart.AddItem(products.SingleOrDefault(x => x.SKU == item.SKU), item.Quantity, item.DateAdded);
                }

                this.Cart.ShippingAddress = existingOrder.ShippingAddress;
                this.Cart.BillingAddress = existingOrder.BillingAddress;

            }

        }
Ejemplo n.º 4
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.Equal(1, cart.Items.Count);
 }
Ejemplo n.º 5
0
        public IList<ShippingMethod> CalculateShipping(ShoppingCart cart) {
            //pull the rates
            var shippingMethods = ShippingMethod.All().ToList();

            //loop the methods and set the cost
            shippingMethods.ForEach(x => x.CalculateCost(cart));
            return shippingMethods;
        }
Ejemplo n.º 6
0
 public void Item_Should_Have_LineTotal_Of_10_With_2_Products_With_Price_5() {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     p.BasePrice = 5;
     cart.AddItem(p);
     cart.AddItem(p);
     Assert.Equal(10, cart.Items[0].LineTotal);
 }
Ejemplo n.º 7
0
        public decimal CalculateTax(ShoppingCart cart) {

            Dictionary<string, decimal> TaxTable = new Dictionary<string, decimal>();
            TaxTable.Add("HI", .0412M);
            TaxTable.Add("CA", .0815M);
            TaxTable.Add("WA", .0612M);


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

            result = rate * cart.SubTotal;

            return result;

        }
Ejemplo n.º 8
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.Equal(2, cart.TotalItems);
 }
Ejemplo n.º 9
0
 public void Total_Should_Be_1_When_1_Product_Added() {
     ShoppingCart cart = new ShoppingCart("TEST");
     cart.AddItem(new Product("SKU"));
     Assert.Equal(1, cart.TotalItems);
 }
Ejemplo n.º 10
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.BasePrice = 90;
            cart.AddItem(p, 1);
            Assert.Equal(90, cart.SubTotal);

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

            Assert.Equal(110, cart.Total);

        }
Ejemplo n.º 11
0
        public void SubTotal_Should_Be_100_When_2_Items_of_Price_5_Adjusted_to_20() {
            ShoppingCart cart = new ShoppingCart("TEST");
            Product p = new Product("SKU");
            p.BasePrice = 5;
            cart.AddItem(p, 1);
            cart.AddItem(p, 1);
            Assert.Equal(10, cart.SubTotal);

            cart.AdjustQuantity(p, 20);
            Assert.Equal(100, cart.SubTotal);

        }
Ejemplo n.º 12
0
        public void ItemLastAdded_Should_Be_Sku2_When_SKu1_Sku2_Added_In_Sequence_Regardless_Of_Adjustments() {
            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));

            cart.AdjustQuantity(p, 10);

            Assert.Equal("SKU2", cart.ItemLastAdded.Product.SKU);

        }
Ejemplo n.º 13
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.Equal(2, cart.Items.Count);

            cart.ClearItems();
            Assert.Equal(0, cart.Items.Count);

        }
Ejemplo n.º 14
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.Equal(1, cart.Items.Count);

            cart.RemoveItem("SKU");
            Assert.Equal(0, cart.Items.Count);

        }
Ejemplo n.º 15
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.Null(item);

        }
Ejemplo n.º 16
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.NotNull(item);

        }
Ejemplo n.º 17
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.Equal(0, cart.Items.Count);
 }
Ejemplo n.º 18
0
 public void TotalItems_Should_Be_9_When_Negative_1_Passed_As_Quantity_To_Existing_10_Items() {
     ShoppingCart cart = new ShoppingCart("TEST");
     Product p = new Product("SKU");
     cart.AddItem(p, 10);
     cart.AddItem(p, -1);
     Assert.Equal(9, cart.TotalItems);
     
 }
Ejemplo n.º 19
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.Equal(0, cart.Items.Count);
 }
Ejemplo n.º 20
0
 public decimal CalculateCost(ShoppingCart cart) {
     _cost = this.BaseRate + (this.RatePerPound * cart.Items.Sum(x => x.Product.WeightInPounds) * cart.Items.Count);
     return _cost;
 }