示例#1
0
        public void Test_MultipleDiscount()
        {
            double expected = 9;

            var repo      = new ItemsRepo();
            var repoItems = repo.GetAllItems();

            var basket = new ShoppingBasket(new ConsoleLogger());

            basket.AddDiscount(new BreadAt50Percent());
            basket.AddDiscount(new FreeMilk());
            basket.AddToBasket(repoItems.Find(i => i.Id == 1)); //butter
            basket.AddToBasket(repoItems.Find(i => i.Id == 1)); //butter
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 3)); //bread

            Assert.AreEqual(expected, basket.RequestTotal(), 0.01);
        }
示例#2
0
        public void Test_FreeMilkDiscount()
        {
            double expected = 3.45;

            var repo      = new ItemsRepo();
            var repoItems = repo.GetAllItems();

            var basket = new ShoppingBasket(new ConsoleLogger());

            basket.AddDiscount(new FreeMilk());
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk
            basket.AddToBasket(repoItems.Find(i => i.Id == 2)); //milk

            Assert.AreEqual(expected, basket.RequestTotal(), 0.01);
        }