public void MatchDiscount10Test()
        {
            var bestRule = _calculator.GetBestRule(1, "DIS10", 1000);

            Assert.Equal("Discount 10%", bestRule.Name);
            Assert.Equal(900, bestRule.Price);
            bestRule = _calculator.GetBestRule(2, "Test", 1000);
            Assert.Equal("Discount 10%", bestRule.Name);
            Assert.Equal(1800, bestRule.Price);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            IConfiguration config         = builder.Build();
            var            discountConfig = new Discount();

            config.GetSection("Discount").Bind(discountConfig);
            var discountRules = DiscountHelper.GetDiscountRuleFromConfig(discountConfig);
            var calculator    = new PriceCalculator(discountRules);

            //due to  important part is Price calculator model, so skip input args and validation here
            //assume all data is correct and invalid data will be reject before this
            Console.WriteLine("-- Start Calculate input");
            Console.WriteLine("Test with 1 person, code DIS10, price 500");
            var bestRule = calculator.GetBestRule(1, "DIS10", 500);

            if (!string.IsNullOrEmpty(bestRule.Name))
            {
                Console.WriteLine("-Match with promotion : " + bestRule.Name.ToString());
                Console.WriteLine("-Amount : " + bestRule.Price.ToString());
            }
            Console.WriteLine("Test with 1 person, code STARCARD, price 2000");
            bestRule = calculator.GetBestRule(1, "STARCARD", 2000);
            if (!string.IsNullOrEmpty(bestRule.Name))
            {
                Console.WriteLine("-Match with promotion : " + bestRule.Name.ToString());
                Console.WriteLine("-Amount : " + bestRule.Price.ToString());
            }
            Console.WriteLine("Test with 2 person, code DIS10, price 1500");
            bestRule = calculator.GetBestRule(2, "DIS10", 1500);
            if (!string.IsNullOrEmpty(bestRule.Name))
            {
                Console.WriteLine("-Match with promotion : " + bestRule.Name.ToString());
                Console.WriteLine("-Amount : " + bestRule.Price.ToString());
            }
            Console.WriteLine("-- End Calculation");
        }