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 IPromotion GetPromoOffer(string productName)
        {
            IPromotion returnVal = null;

            if (productName == "A")
            {
                returnVal = new PromotionA();
            }
            else if (productName == "B")
            {
                returnVal = new PromotionB();
            }
            return(returnVal);
        }
Ejemplo n.º 4
0
        public void Can_Calculate_Promotional_Discount(int promotionQuantityWhenBought,
                                                       int promotionQuantityOffered,
                                                       int promotionalDiscountOffered,
                                                       int numberOfItemsBought,
                                                       decimal originalPrice,
                                                       decimal expectedPrice)
        {
            IPromotion           promotion           = new Promotion("TestPromotion", 1000, promotionQuantityWhenBought, promotionQuantityOffered, promotionalDiscountOffered);
            IPromotionCalculator promotionCalculator = new PromotionA(promotion);
            decimal promotionalPrice = promotionCalculator.Calculate(numberOfItemsBought, originalPrice);
            string  appliedPromotion = promotionCalculator.GetAppliedPromotion();

            Assert.Equal(expectedPrice, promotionalPrice);
            Assert.Equal($"Buy {promotionQuantityWhenBought} - Get {promotionQuantityOffered} @ {promotionalDiscountOffered} off ", appliedPromotion, true);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            List <Product> products = new List <Product>();

            foreach (ProductType productT in Enum.GetValues(typeof(ProductType)))
            {
                Console.WriteLine("Please enter the quantity for product type " + productT);
                bool isInvalid = true;
                int  quantity  = 0;
                while (isInvalid)
                {
                    string input = Console.ReadLine();
                    if (int.TryParse(input, out quantity))
                    {
                        isInvalid = false;
                    }
                    else
                    {
                        Console.WriteLine("Not and integer, please try again.");
                    }
                }

                Product product = new Product();
                product.Sku      = productT;
                product.Quantity = quantity;

                products.Add(product);
            }

            PromotionA promotionA = new PromotionA();

            promotionA.SetNext(new PromotionB()).SetNext(new PromotionCD());

            Console.WriteLine("Total Price of the cart: " + promotionA.Handle(products));
            Console.ReadKey();
        }
Ejemplo n.º 6
0
 public void Setup()
 {
     promotionA = new PromotionA();
     promotionA.SetNext(new PromotionB()).SetNext(new PromotionCD());
 }