예제 #1
0
 public void CalculateDiscount(Order o)
 {
     double discount = 0;
     foreach (OrderItem oi in o.Items)
     {
         if (oi.Qty > 1)
         {
             discount += oi.Product.Price * (oi.Qty / 2) * 30/100;
         }
     }
     o.Discount = discount;
 }
예제 #2
0
        public void D1WhenBuying2ApplyOnlyOnSecondItem()
        {
            Product p = new Product();
            p.Sku = "100.1";
            p.Name = "Umbrella";
            p.Price = 20;

            Order order = new Order();
            order.Add(p, 2);

            DiscountEngine de = new DiscountEngine();
            de.CalculateDiscount(order);

            Assert.AreEqual(6, order.Discount);
        }
예제 #3
0
        public void D1NotAppliedWhenBuying1Item()
        {
            //setup
            Product p = new Product();
            p.Sku = "100.1";
            p.Name = "Umbrella";
            p.Price = 20;

            Order order = new Order();
            order.Add(p,1);

            DiscountEngine de = new DiscountEngine();

            //exercise
            de.CalculateDiscount(order);

            //verify
            Assert.AreEqual(0, order.Discount);
        }