コード例 #1
0
 public void AddItemTest_withQuantity_itemInCartAlready_itemAddedWithQuantity() {
     ShoppingCart cart = new ShoppingCart();
     Item item = new Item("Apple");
     cart.AddItem(item, 3);
     Assert.IsTrue(cart.DoesCartContainItem(item));
     Assert.AreEqual(3, cart.GetLineItemForItem(item).Quantity);
     cart.AddItem(item, 4);
     Assert.AreEqual(7, cart.GetLineItemForItem(item).Quantity);
 }
コード例 #2
0
        public void AddItemTest_itemInCart_addsAdditionalItemToLineItemCount() {
            ShoppingCart cart = new ShoppingCart();
            Item item = new Item("Apple");
            cart.AddItem(item);

            Assert.IsTrue(cart.DoesCartContainItem(item));
            Assert.AreEqual(1, cart.CountOfItems);

            cart.AddItem(item);
            Assert.AreEqual(1, cart.CountOfItems);
            LineItem lineItem = cart.GetLineItemForItem(item);
            Assert.AreEqual(2, lineItem.Quantity);
        }
コード例 #3
0
        public void AddItemTest_itemNotInCart_addsItem() {
            ShoppingCart cart = new ShoppingCart();
            Assert.AreEqual(0, cart.CountOfItems);

            Item item = new Item("Apple");
            cart.AddItem(item);
            Assert.IsTrue(cart.DoesCartContainItem(item));
            Assert.AreEqual(1, cart.CountOfItems);
        }
コード例 #4
0
        public ShoppingCart GetShoppingCart(String filename) {
            if (!File.Exists(filename)) {
                Console.WriteLine("File does not exist: " + filename);
                return new ShoppingCart();
            }

            string[] items = File.ReadAllLines(filename);

            ShoppingCart cart = new ShoppingCart();
            foreach (string item in items) {
                if (item.Trim().Length == 0) {
                    continue;
                }
                cart.AddItem(new Item(item.Trim()));
            }
            return cart;
        }
コード例 #5
0
        public void GetTotalTest_validTotalsReturned() {
            ShoppingCart cart = new ShoppingCart();
            Item apple = new Item("Apple");
            Item bananas = new Item("Bananas");

            cart.AddItem(apple, 3);
            cart.AddItem(bananas, 3);

            LineItem applesLineItem = cart.GetLineItemForItem(apple);
            applesLineItem.PricePerUnit = 2.00;

            LineItem bananasLineItem = cart.GetLineItemForItem(bananas);
            bananasLineItem.PricePerUnit = 3.00;

            Assert.AreEqual(15.00, cart.GetTotal());
        }
コード例 #6
0
 public void AddItemTest_withQuantity_negativeQuantity_expectException() {
     ShoppingCart cart = new ShoppingCart();
     cart.AddItem(new Item("Apple"), -1);
 }
コード例 #7
0
 public void AddItemTest_withQuantity_nullItem_expectException() {
     ShoppingCart cart = new ShoppingCart();
     cart.AddItem(null, 1);
 }
コード例 #8
0
 public void DoesCartHaveGreaterThanOrEqualItems_itemInCart_quantityIsNotGreater_returnsFalse() {
     ShoppingCart cart = new ShoppingCart();
     Item item = new Item("Apple");
     cart.AddItem(item, 1);
     Assert.IsFalse(cart.DoesCartHaveGreaterThanOrEqualItems(item, 3));
 }
コード例 #9
0
 public void AttachPromotionToItemTest_itemNotInCart_nothingHappens() {
     ShoppingCart cart = new ShoppingCart();
     Item item = new Item("Apple");
     Item item2 = new Item("Bananas");
     cart.AddItem(item);
     cart.AttachPromotionToItem(item2, new QuantityPricePromotion(item2, "[email protected]"));
     LineItem lineItem = cart.GetLineItemForItem(item);
     Assert.IsNull(lineItem.Promotion);
 }
コード例 #10
0
 public void AddItemTest_itemIsNull_expectException() {
     ShoppingCart cart = new ShoppingCart();
     cart.AddItem(null);
 }
コード例 #11
0
 public void GetLineItemForItemTest_itemInCart_returnsNull() {
     ShoppingCart cart = new ShoppingCart();
     Item item = new Item("Apple");
     cart.AddItem(item);
     LineItem lineItem = cart.GetLineItemForItem(item);
     Assert.IsNotNull(lineItem);
 }