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); }
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); }
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); }
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; }
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()); }
public void AddItemTest_withQuantity_negativeQuantity_expectException() { ShoppingCart cart = new ShoppingCart(); cart.AddItem(new Item("Apple"), -1); }
public void AddItemTest_withQuantity_nullItem_expectException() { ShoppingCart cart = new ShoppingCart(); cart.AddItem(null, 1); }
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)); }
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); }
public void AddItemTest_itemIsNull_expectException() { ShoppingCart cart = new ShoppingCart(); cart.AddItem(null); }
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); }