コード例 #1
0
        public void None()
        {
            var d = new UnidaysDiscountChallenge(Rules);

            var result = d.CalculateTotalPrice();

            Assert.Equal(0, result.Total);
            Assert.Equal(0, result.DeliveryCharge);
        }
コード例 #2
0
        public void E()
        {
            var d = new UnidaysDiscountChallenge(Rules);

            d.AddToBasket(Items[4]);

            var result = d.CalculateTotalPrice();

            Assert.Equal(5, result.Total);
            Assert.Equal(7, result.DeliveryCharge);
        }
コード例 #3
0
        public void DDDDDDDDDDDDDD()
        {
            var d = new UnidaysDiscountChallenge(Rules);

            for (var i = 0; i < 14; i++)
            {
                d.AddToBasket(Items[3]);
            }

            var result = d.CalculateTotalPrice();

            Assert.Equal(49, result.Total);
            Assert.Equal(7, result.DeliveryCharge);
        }
コード例 #4
0
        // This simple console app is an example of how the interface may be used
        static void Main(string[] args)
        {
            // Create the items that were given in the challenge
            var itemA = new Item {
                Id = 'A', Price = 8
            };
            var itemB = new Item {
                Id = 'B', Price = 12
            };
            var itemC = new Item {
                Id = 'C', Price = 4
            };
            var itemD = new Item {
                Id = 'D', Price = 7
            };
            var itemE = new Item {
                Id = 'E', Price = 5
            };

            // Create the rules for the items that were given in the challenge
            // A doesn't have a pricing rule that would apply a discount so we skip it
            var ruleB = new NItemsForXPricingRule(itemB, 2, 20);
            var ruleC = new NItemsForXPricingRule(itemC, 3, 10);
            var ruleD = new Buy1Get1FreePricingRule(itemD);
            var ruleE = new NItemsForThePriceOfXItemsPricingRule(itemE, 3, 2);

            var pricingRules = new List <IPricingRule> {
                ruleB, ruleC, ruleD, ruleE
            };

            // Initialize our UnidaysDiscountChallenge with the set of pricing rules
            var example = new UnidaysDiscountChallenge(pricingRules);

            // Add some items to the basket
            example.AddToBasket(itemD);
            example.AddToBasket(itemD);

            // Get amount to pay
            var result = example.CalculateTotalPrice();

            var totalPrice     = result.Total;
            var deliveryCharge = result.DeliveryCharge;
            var overallTotal   = totalPrice + deliveryCharge;

            Console.WriteLine("Items in the basket: DD");
            Console.WriteLine($"\nPrice after discounts: £{totalPrice:0.00}");
            Console.WriteLine($"Delivery charge: £{deliveryCharge:0.00}");
            Console.WriteLine($"Overall total: £{overallTotal:0.00}");
        }
コード例 #5
0
        public void BBBBCCC()
        {
            var d = new UnidaysDiscountChallenge(Rules);

            for (var i = 0; i < 4; i++)
            {
                d.AddToBasket(Items[1]);
            }

            for (var i = 0; i < 3; i++)
            {
                d.AddToBasket(Items[2]);
            }

            var result = d.CalculateTotalPrice();

            Assert.Equal(50, result.Total);
            Assert.Equal(0, result.DeliveryCharge);
        }