public void ConstructorTest() { var product = new Product("A", 2.00, discounts); var item = new CartItem(product.GetName(), product, 1); Assert.AreEqual(product.GetName(), item.GetName()); Assert.AreEqual(product, item.GetProduct()); }
public void CalculatePriceTest() { var product = new Product("A", 2.00, discounts); var item = new CartItem(product.GetName(), product, 1); var item2 = new CartItem(product.GetName(), product, 2); Assert.AreEqual(item.CalculatePrice(), 2.00); Assert.AreEqual(item2.CalculatePrice(), 4.00); }
public void CalculateDiscountTest() { var product = new Product("A", 2.00, discounts); var item = new CartItem(product.GetName(), product, 4); var item2 = new CartItem(product.GetName(), product, 5); var item3 = new CartItem(product.GetName(), product, 10); Assert.AreEqual(item.CalculateDiscount(), 1.00); Assert.AreEqual(item2.CalculateDiscount(), 1.00); Assert.AreEqual(item3.CalculateDiscount(), 2.00); }
/* * Adds a CartItem to the cart and sets the quanity of that CartItem */ public void AddItem(Product product, int quantity) { if (_contents.ContainsKey(product.GetName())) { _contents[product.GetName()].quantity += quantity; } else { var item = new CartItem(product.GetName(), product, quantity); _contents[product.GetName()] = item; } }