Ejemplo n.º 1
0
        public void Should_calculateWithoutDiscount()
        {
            List <Product> products = new List <Product>()
            {
                new Product
                {
                    Sku      = ProductType.A,
                    Quantity = 1
                },
                new Product
                {
                    Sku      = ProductType.B,
                    Quantity = 1
                },
                new Product
                {
                    Sku      = ProductType.C,
                    Quantity = 0
                },
                new Product
                {
                    Sku      = ProductType.D,
                    Quantity = 1
                }
            };

            var output = promotionA.Handle(products);

            Assert.AreEqual(95.0f, output);
        }
Ejemplo n.º 2
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();
        }