Example #1
0
        public void Basket_4Milk_Total_3Pounds45()
        {
            var basket   = new Basket();
            var products = Enumerable.Repeat(ProductMocks.Milk, 4);

            basket.AddProducts(products);
            var milkOffer = new MilkOffer();

            decimal total = basket
                            .WithOffers(milkOffer)
                            .GetTotal();

            Assert.AreEqual(3.45m, total);
        }
Example #2
0
        public void Basket_With_3Pounds_Products_Total_3Pounds()
        {
            var basket   = new Basket();
            var products = new List <Product>
            {
                new Product(string.Empty, 1),
                new Product(string.Empty, 2)
            };

            basket.AddProducts(products);

            decimal total = basket.GetTotal();

            Assert.AreEqual(3m, total);
        }
Example #3
0
        public void Add_Products_Basket_Should_Have_Those_Products()
        {
            var basket   = new Basket();
            var products = new List <Product>
            {
                new Product("0", 0),
                new Product("1", 1)
            };

            basket.AddProducts(products);

            Assert.AreEqual(products.Count, basket.Products.Count);
            Assert.AreSame(products[0], basket.Products[0]);
            Assert.AreSame(products[1], basket.Products[1]);
        }
Example #4
0
        public void Basket_1Bread_1Butter_1Milk_Total_2Pounds95()
        {
            var basket   = new Basket();
            var products = new List <Product>
            {
                ProductMocks.Bread,
                ProductMocks.Butter,
                ProductMocks.Milk
            };

            basket.AddProducts(products);

            decimal total = basket.GetTotal();

            Assert.AreEqual(2.95m, total);
        }
Example #5
0
        public void Basket_2Butter_2Bread_Total_3Pounds10()
        {
            var basket   = new Basket();
            var products = new List <Product>
            {
                ProductMocks.Bread,
                ProductMocks.Bread,
                ProductMocks.Butter,
                ProductMocks.Butter
            };

            basket.AddProducts(products);
            var butterOffer = new ButterOffer();

            decimal total = basket
                            .WithOffers(butterOffer)
                            .GetTotal();

            Assert.AreEqual(3.1m, total);
        }
Example #6
0
        public void Basket_Duplicate_Offers_DoNot_Cumulate()
        {
            var basket   = new Basket();
            var products = Enumerable.Repeat(ProductMocks.Milk, 8).ToList();

            products.AddRange(new List <Product>
            {
                ProductMocks.Bread,
                ProductMocks.Butter,
                ProductMocks.Butter
            });
            Enumerable.Repeat(ProductMocks.Milk, 8);
            basket.AddProducts(products);
            var butterOffer = new ButterOffer();
            var milkOffer   = new MilkOffer();

            decimal total = basket
                            .WithOffers(butterOffer, milkOffer, milkOffer, butterOffer)
                            .GetTotal();

            Assert.AreEqual(9, total);
        }
Example #7
0
        static void Main(string[] args)
        {
            var productRepository  = new ProductRepository();
            var ruleRepository     = new RuleRepository(productRepository);
            var discountRepository = new DiscountRepository(ruleRepository, productRepository);

            var compiler          = new DiscountCompiler();
            var compiledDiscounts = compiler.Compile(discountRepository.GetFromSource());

            var discountManager = new DiscountManager(compiledDiscounts);

            var basket = new Basket(discountManager);

            var products = productRepository.GetFromSource().ToArray();
            var butter   = products[0];
            var milk     = products[1];
            var bread    = products[2];

            basket.AddProducts(new BasketItem(1, butter), new BasketItem(1, milk), new BasketItem(1, bread));

            var logger = new FileLogger();

            Console.WriteLine("Case 1: ");
            var summary1 = basket.CalculateSum();

            Console.WriteLine(summary1);
            logger.Log(summary1);

            basket.Clear();
            basket.AddProducts(new BasketItem(2, butter), new BasketItem(2, bread));

            Console.WriteLine("Case 2: ");
            var summary2 = basket.CalculateSum();

            Console.WriteLine(summary2);
            logger.Log(summary2);

            basket.Clear();
            basket.AddProducts(new BasketItem(4, milk));

            Console.WriteLine("Case 3: ");
            var summary3 = basket.CalculateSum();

            Console.WriteLine(summary3);
            logger.Log(summary3);

            basket.Clear();
            basket.AddProducts(new BasketItem(2, butter), new BasketItem(1, bread), new BasketItem(8, milk));

            Console.WriteLine("Case 4:");
            var summary4 = basket.CalculateSum();

            Console.WriteLine(summary4);
            logger.Log(summary4);

            basket.Clear();
            basket.AddProducts(new BasketItem(2, butter), new BasketItem(1, bread), new BasketItem(9, milk));

            Console.WriteLine("Case 5:");
            var summary5 = basket.CalculateSum();

            Console.WriteLine(summary5);
            logger.Log(summary5);
        }