Esempio n. 1
0
 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());
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 /*
  * 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;
     }
 }
Esempio n. 5
0
 public void NoDiscountTest()
 {
     var a = new Product("A", 2.00);
     Assert.AreEqual(a.GetName(), "A");
     Assert.AreEqual(a.GetPrice(), 2.00);
     Assert.AreEqual(a.GetDiscounts(), new Discount[]{});
 }
Esempio n. 6
0
        public void ConstructorTest()
        {
            var discount = new VolumeDiscount(7.00, 4);
            var discounts = new Discount[] { discount };

            var a = new Product("A", 2.00, discounts);
            Assert.AreEqual(a.GetName(), "A");
            Assert.AreEqual(a.GetPrice(), 2.00);
            Assert.AreEqual(a.GetDiscounts(), discounts);
        }