internal IPromotion GetManager(string sku)
        {
            IPromotion promotion = null;

            switch (sku.ToUpper())
            {
            case "A":
                promotion = new PromotionA(new A());
                break;

            case "B":
                promotion = new PromotionB(new B());
                break;

            case "C":
                promotion = new PromotionC(new C());
                break;

            case "D":
                promotion = new PromotionD(new D());
                break;

            default:
                break;
            }
            return(promotion);
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            List <ISKU> ScenarioA = new List <ISKU> {
                new skuA(), new skuB(), new skuC()
            };
            int cost = new PromotionA(ScenarioA).Cost();

            Assert.AreEqual(cost, 50);
            cost = new PromotionB(ScenarioA).Cost();
            Assert.AreEqual(cost, 30);
            cost = new PromotionCD(ScenarioA).Cost();
            Assert.AreEqual(cost, 20);
        }
Ejemplo n.º 3
0
        public void Can_Calculate_Promotional_Group_Discount(int promotionQuantityWhenBought,
                                                             int promotionalDiscountOffered,
                                                             int numberOfItemsBought,
                                                             decimal originalPrice,
                                                             decimal expectedPrice)
        {
            IPromotion           promotion           = new Promotion("TestPromotion", 1000, promotionQuantityWhenBought, 0, promotionalDiscountOffered);
            IPromotionCalculator promotionCalculator = new PromotionB(promotion);
            decimal promotionalPrice = promotionCalculator.Calculate(numberOfItemsBought, originalPrice);
            string  appliedPromotion = promotionCalculator.GetAppliedPromotion();

            Assert.Equal(expectedPrice, promotionalPrice);
            Assert.Equal($"Buy Groups of {promotionQuantityWhenBought} @ {promotionalDiscountOffered} ", appliedPromotion, true);
        }
Ejemplo n.º 4
0
        public IPromotion GetPromoOffer(string productName)
        {
            IPromotion returnVal = null;

            if (productName == "A")
            {
                returnVal = new PromotionA();
            }
            else if (productName == "B")
            {
                returnVal = new PromotionB();
            }
            return(returnVal);
        }