Exemplo n.º 1
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[]{});
 }
Exemplo n.º 2
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());
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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;
     }
 }
Exemplo n.º 7
0
 public void Init()
 {
     discount = new VolumeDiscount(7.00, 4);
     discount2 = new VolumeDiscount(6.00, 6);
     discounts = new Discount[] { discount };
     discounts2 = new Discount[] { discount2 };
     product = new Product("A", 2.00, discounts);
     product2 = new Product("B", 12.00);
     product3 = new Product("C", 1.25, discounts2);
     product4 = new Product("D", 0.15);
 }
Exemplo n.º 8
0
 /*
  * Create cart item with it's name, the product it refers to, and the quantity
  */
 public CartItem(string productName, Product prod, int quant)
 {
     _name = productName;
     quantity = quant;
     _product = prod;
 }