public void Define_QuantityDiscountPricingRule_A_5_for_the_Price_of_4()
        {
            QuantityDiscountPricingRule rule = new QuantityDiscountPricingRule("A", 5, 4);
            int discountQty = rule.GetTotalDiscountQuantity(5);
            decimal expectedDiscountQty = 4;

            Assert.AreEqual(expectedDiscountQty, discountQty);
        }
Exemple #2
0
        public decimal GetItemTotalPrice(string item, int totalQuantity)
        {
            IEnumerable <IPricingRule> sortedRules = this.GetPricingRulesSortedByPriority();
            var sortedItemRules = sortedRules.Where(r => r.Sku == item);

            decimal itemTotalPrice = 0;

            int restQuantity = totalQuantity;

            bool foundQtyDiscountRule = false;

            foreach (var itemRule in sortedItemRules)
            {
                if (!foundQtyDiscountRule)
                {
                    QuantityDiscountPricingRule qtyDiscountRule = itemRule as QuantityDiscountPricingRule;
                    if (qtyDiscountRule != null)
                    {
                        foundQtyDiscountRule = true;
                        restQuantity         = qtyDiscountRule.GetTotalDiscountQuantity(restQuantity);

                        continue;
                    }
                }
                else
                {
                    // ignore the other quantity discount rules
                }

                QuantityPricingRule qtyRule = itemRule as QuantityPricingRule;
                if (qtyRule != null)
                {
                    int multiple = restQuantity / qtyRule.Quantity;
                    restQuantity    = restQuantity % qtyRule.Quantity;
                    itemTotalPrice += qtyRule.GetPrice() * multiple;

                    continue;
                }
            }

            return(itemTotalPrice);
        }
 public void AddQuantityDiscountPricingRule(QuantityDiscountPricingRule rule)
 {
     pricingRuleList.Add(rule);
 }
 public void QuantityDiscountPricingRule_Quantity_LessThan_DiscountQuantity_Throws_Exception()
 {
     QuantityDiscountPricingRule rule = new QuantityDiscountPricingRule("A", 2, 3);
 }
Exemple #5
0
 public void AddQuantityDiscountPricingRule(QuantityDiscountPricingRule rule)
 {
     pricingRuleList.Add(rule);
 }