예제 #1
0
        public void Offer_50Percent_Bread_Discount_Per_2Butter()
        {
            var butterOffer = new ButterOffer();
            var products    = new List <Product>
            {
                ProductMocks.Bread,
                ProductMocks.Butter,
                ProductMocks.Butter
            };

            Func <IEnumerable <Product>, decimal> discountCalculator = butterOffer.GetDiscountCalculator();
            var discount = discountCalculator(products);

            Assert.AreEqual(0.5m, discount);
        }
예제 #2
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);
        }
예제 #3
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);
        }