예제 #1
0
        public void Cashier_WhenNoProducts_PriceIsZero()
        {
            var cashier  = new Cashier(GetPricingStrategies());
            var products = new List <Sku>();

            var price = cashier.Checkout(products);

            Assert.AreEqual(0, price);
        }
예제 #2
0
        public void Cashier_OneB_Is30()
        {
            var cashier  = new Cashier(GetPricingStrategies());
            var products = new List <Sku>()
            {
                'B'
            };

            var price = cashier.Checkout(products);

            Assert.AreEqual(30, price);
        }
예제 #3
0
        public void Cashier_SixA_Is260()
        {
            var cashier  = new Cashier(GetPricingStrategies());
            var products = new List <Sku>()
            {
                'A', 'A', 'A', 'A', 'A', 'A'
            };

            var price = cashier.Checkout(products);

            Assert.AreEqual(260, price);
        }
예제 #4
0
        public void Cashier_TwoC_Is20()
        {
            var cashier  = new Cashier(GetPricingStrategies());
            var products = new List <Sku>()
            {
                'C', 'C'
            };

            var price = cashier.Checkout(products);

            Assert.AreEqual(40, price);
        }
예제 #5
0
        public void Cashier_OneATwoB_OutOfOrder_Is95()
        {
            var cashier  = new Cashier(GetPricingStrategies());
            var products = new List <Sku>()
            {
                'B', 'A', 'B'
            };

            var price = cashier.Checkout(products);

            Assert.AreEqual(95, price);
        }
예제 #6
0
        public void Cashier_ThreeBIs75()
        {
            var cashier  = new Cashier(GetPricingStrategies());
            var products = new List <Sku>()
            {
                'B', 'B', 'B'
            };

            var price = cashier.Checkout(products);

            Assert.AreEqual(75, price);
        }
예제 #7
0
        public static void GetPromotions(string sKuInputs)
        {
            char[] Skus = sKuInputs.ToCharArray();
            if (Skus.Length == 0)
            {
                // Display message to user to provide parameters.
                Console.WriteLine("Please enter Valid SKU IDs.");
                return;
            }
            else
            {
                var SkusA  = Skus.Where(x => x == 'A').ToList();
                var SkusB  = Skus.Where(x => x == 'B').ToList();
                var SkusC  = Skus.Where(x => x == 'C').ToList();
                var SkusD  = Skus.Where(x => x == 'D').ToList();
                var SkusCD = Skus.Where(x => x == 'C' || x == 'D').ToList();

                var         strategies   = new List <object>();
                IList <Sku> objSkus      = new List <Sku>();
                bool        isAddedItems = false;

                if (SkusC != null && SkusD != null)
                {
                    if (SkusC.Count > 0 && SkusD.Count > 0)
                    {
                        isAddedItems = true;
                    }
                }
                foreach (Char sku in Skus)
                {
                    if (sku == 'A' || sku == 'B')
                    {
                        objSkus.Add(new Sku(sku));
                    }
                    if (!isAddedItems && (sku == 'C' || sku == 'D'))
                    {
                        objSkus.Add(new Sku(sku));
                    }
                }

                if (isAddedItems)
                {
                    objSkus.Add(new Sku('&'));
                }

                if (SkusA != null)
                {
                    IPricingStrategy strategyA = new PricingStategyA();
                    strategies.Add(strategyA);
                }
                if (SkusB != null)
                {
                    IPricingStrategy strategyB = new PricingStrategyB();
                    strategies.Add(strategyB);
                }


                if (SkusCD != null && SkusCD.Count >= 2)
                {
                    IPricingStrategy strategyCandD = new PricingStrategyCandD();
                    // strategyCandD.Sku = '&';
                    strategies.Add(strategyCandD);
                }
                else if (SkusC != null && SkusC.Count > 0)
                {
                    IPricingStrategy strategyC = new PricingStrategyC();

                    strategies.Add(strategyC);
                }
                else if (SkusD != null && SkusD.Count > 0)
                {
                    IPricingStrategy strategyD = new PricingStrategyD();
                    strategies.Add(strategyD);
                }



                //List<IPricingStrategy>  objStrategies =strategies.
                List <IPricingStrategy> fooList = strategies.OfType <IPricingStrategy>().ToList();
                Cashier cashier   = new Cashier(fooList);
                double  intResult = cashier.Checkout(objSkus);

                Console.WriteLine("The Total Order value " + intResult);
            }

            Console.Read();
        }