public void Test2ABuy1Item()
        {
            //setup
            Promotion promo = new PromotionTwo(); //TODO: setup the promotion as you see fit
            DiscountCalculator dc = new DiscountCalculator(promo);

            Order o = new Order();
            o.Add(Products.GetProduct("blueDress"), 1);
            //o.Add(Products.GetProduct("redDress"), 3);
            //o.Add(Products.GetProduct("greenDress"), 3);
            //o.Add(Products.GetProduct("whiteSocks"), 1);
            //o.Add(Products.GetProduct("redSocks"), 3);

            //exercise
            Order newOrder = dc.CalculateDiscount(o);

            //verify
            double expectedValue = 90;

            Assert.AreEqual(expectedValue, newOrder.TotalPrice, 0.001);
            //TODO: add additional verification if necessary
        }
Example #2
0
        static void Main(string[] args)
        {
            //Test1ABuy1Item();
            Order order = new Order();
            Promotion promo = new PromotionOne(); //TODO: setup the promotion as you see fit
            order.Promotion = promo;
            //DiscountCalculator dc = new DiscountCalculator(promo);
            List<Order> orders = new List<Order>();
            orders.Add(order);
            while (true)
            {

                Console.WriteLine(DisplayMainMenu());
                String a = Console.ReadLine();

                int optionSelected;
                if (Int32.TryParse(a, out optionSelected))
                {
                    switch (optionSelected)
                    {
                        case 1:
                            int optionSelected2 = -1;
                            while (optionSelected2 != 0)
                            {
                                Console.WriteLine(DisplayProductMenu());
                                String b = Console.ReadLine();
                                if (Int32.TryParse(b, out optionSelected2))
                                {

                                    switch (optionSelected2)
                                    {
                                        case 1:
                                            order.Add(Products.GetProduct("blueDress"), 1);
                                            break;
                                        case 2:
                                            order.Add(Products.GetProduct("redDress"), 1);
                                            break;
                                        case 3:
                                            order.Add(Products.GetProduct("greenDress"), 1);
                                            break;
                                        case 4:
                                            order.Add(Products.GetProduct("whiteSocks"), 1);
                                            break;
                                        case 5:
                                            order.Add(Products.GetProduct("redSocks"), 1);
                                            break;
                                    }

                                    Console.WriteLine("======Total Price: " + order.TotalPrice + "======");
                                }
                            }

                            break;
                        case 2:
                            Console.WriteLine(order.toString());
                            break;
                        case 3:
                            Console.WriteLine(DisplayPromotionType());
                            String c = Console.ReadLine();
                            int optionSelected3 = -1;
                            if (Int32.TryParse(c, out optionSelected3))
                            {
                                Promotion promotion = order.Promotion;
                                switch (optionSelected3)
                                {
                                    case 1:
                                        promotion = new PromotionOne();
                                        break;
                                    case 2:
                                        promotion = new PromotionTwo();
                                        break;
                                    case 3:
                                        promotion = new PromotionThree();
                                        break;
                                    case 4:
                                        promotion = null;
                                        break;
                                    case 0:
                                        break;
                                    default:
                                        break;
                                }
                                order.Promotion = promotion;

                                Console.WriteLine("======Total Price with selected Promotion: " + order.TotalPrice + "======");
                            }
                            break;
                        case 4:
                            Console.WriteLine("======Total Price: " + order.TotalPrice + "======");
                            break;
                        case 5:
                            order = new Order();
                            orders.Add(order);
                            break;
                        case 6:
                            Console.WriteLine("Checking out is not yet supported.");
                            break;
                    }
                }

            }
        }