Пример #1
0
        public void AddItemToCartTest()
        {
            ShopModel tempModel = new ShopModel();

            tempModel.shoppingCart = new Dictionary <Item, int>();
            Item item1 = new Item
            {
                itemID       = 1,
                name         = "Item1",
                sellingPrice = 50
            };

            tempModel.shoppingCart.Add(item1, 5); // added 5 of item 1 to cart.
            Item item2 = new Item
            {
                itemID       = 2,
                name         = "Item2",
                sellingPrice = 50
            };

            CheckoutFacilitator.AddItemToCart(item2, 3, tempModel); // add new item to cart

            // cart should have 8 items total, and 2 entreis in the cart.

            if (tempModel.shoppingCart.Count != 2)
            {
                Assert.Fail();
            }
            if (tempModel.shoppingCart.Sum(x => x.Value) != 8)
            {
                Assert.Fail();
            }
        }
Пример #2
0
        public void GetCartTotalTest()
        {
            Dictionary <Item, int> cart = new Dictionary <Item, int>();

            Item item1 = new Item
            {
                sellingPrice = 50
            };

            cart.Add(item1, 5); // 5 * 50 = 250

            Item item2 = new Item
            {
                sellingPrice = 20
            };

            cart.Add(item2, 2); // 20 * 2 = 40

            // cart total should be 290.

            var total = CheckoutFacilitator.GetCartTotal(cart);

            if (total != 290)
            {
                Assert.Fail(); // if total not 290, fail test.
            }
        }
Пример #3
0
        public void CreateOrder(string firstName, string lastName, string email, string phone, string shippingStreet, string shippingCity,
                                string shippingPostcode, string shippingState, string billingStreet, string billingCity, string billingPostcode, string billingState, string billingMethod)
        {
            model = (ShopModel)Session["model"]; // get the model object

            model.currentReceipt = CheckoutFacilitator.CreateOrder(firstName, lastName, email, phone, shippingStreet, shippingCity,
                                                                   shippingPostcode, shippingState, billingStreet, billingCity, billingPostcode, billingState, billingMethod, model);

            //clear cart - we don't need it any more!
            model.shoppingCart.Clear();
            Session["model"] = model; // reassign model.
        }
Пример #4
0
        public void DeleteItemFromCart(string itemId)
        {
            model = (ShopModel)Session["model"]; // get the model object
            Item currentItem = null;

            // For each item in the item catalog, check whether the item's ID matches the
            // input ID.
            foreach (var i in model.itemCatalog)
            {
                if (i.itemID == Int32.Parse(itemId) /*Parse Item ID, TODO: exception handling... */)
                {
                    currentItem = i; break; // there is a match - store the matching item and break out of the loop
                }
            }

            if (currentItem != null) // if we have found an item
            {
                model.shoppingCart = CheckoutFacilitator.RemoveItemFromCart(currentItem, model);
            }
            Session["model"] = model; // reassign model.
        }
Пример #5
0
        public void EditQuantityTest()
        {
            ShopModel tempModel = new ShopModel();

            tempModel.shoppingCart = new Dictionary <Item, int>();
            Item item1 = new Item
            {
                itemID       = 1,
                name         = "Item1",
                sellingPrice = 50
            };

            tempModel.shoppingCart.Add(item1, 5);                  // added 5 of item 1 to cart.

            CheckoutFacilitator.EditQuantity(item1, 2, tempModel); // should now have 2 of item1

            if (tempModel.shoppingCart[item1] != 2)
            {
                Assert.Fail();
            }
        }
Пример #6
0
        public void RemoveItemFromCartTest()
        {
            ShopModel tempModel = new ShopModel();

            tempModel.shoppingCart = new Dictionary <Item, int>();
            Item item1 = new Item
            {
                itemID       = 1,
                name         = "Item1",
                sellingPrice = 50
            };

            tempModel.shoppingCart.Add(item1, 5); // added 5 of item 1 to cart.
            Item item2 = new Item
            {
                itemID       = 2,
                name         = "Item2",
                sellingPrice = 50
            };

            tempModel.shoppingCart.Add(item2, 2); // currently cart should have 8 items total, and 2 entries in the cart.

            // now remove item 2

            CheckoutFacilitator.RemoveItemFromCart(item2, tempModel);

            // now should only have 1 entry, which should be item 1.
            if (tempModel.shoppingCart.Count != 1)
            {
                Assert.Fail();
            }
            if (tempModel.shoppingCart.ContainsKey(item2))
            {
                Assert.Fail();
            }
            if (tempModel.shoppingCart.Sum(x => x.Value) != 5) // should have a qty of 5
            {
                Assert.Fail();
            }
        }