private static void SmartHappyHoursOrderCalculatorTest()
        {
            Customer customer = new Customer("Anna", "Kowalska");

            Order order = CreateOrder(customer);

            ICanDiscountStrategy       canDiscountStrategy       = new HappyHoursCanDiscountStrategy(TimeSpan.Parse("09:00"), TimeSpan.Parse("16:00"));
            ICalculateDiscountStrategy calculateDiscountStrategy = new PercentageCalculateDiscountStrategy(0.2m);

            SmartDiscountOrderCalculator calculator = new SmartDiscountOrderCalculator(canDiscountStrategy, calculateDiscountStrategy);

            decimal discount = calculator.CalculateDiscount(order);

            Console.WriteLine($"Original amount: {order.Amount:C2} Discount: {discount:C2}");
        }
Exemplo n.º 2
0
        public static void Test()
        {
            Customer customer = new Customer("Anna", "Kowalska");
            Order    order    = CreateOrder(customer);

            ICanDiscountStrategy canDiscountStrategy = new HappyHoursCanDiscountStrategy(TimeSpan.Parse("9:30"), TimeSpan.Parse("16"));
            IDiscountStrategy    discountStrategy    = new PercentageDiscountStrategy(0.1m);

            // PMC> Install-Package Newtonsoft.Json
            string            jsonDiscountStrategy = JsonConvert.SerializeObject(discountStrategy);
            IDiscountStrategy discountStrategy2    = JsonConvert.DeserializeObject <PercentageDiscountStrategy>(jsonDiscountStrategy);

            OrderDiscountCalculator discountCalculator = new OrderDiscountCalculator(canDiscountStrategy, discountStrategy);

            decimal discount = discountCalculator.CalculateDiscount(order);
        }
Exemplo n.º 3
0
        private static void HappyHoursOrderCalculatorTest()
        {
            Customer customer = new Customer("Anna", "Kowalska");

            Order order = CreateOrder(customer);

            // HappyHoursDiscountStrategy discountStrategy = new HappyHoursDiscountStrategy(TimeSpan.Parse("09:00"), TimeSpan.Parse("16:30"), 0.1m);

            // GenderDiscountStrategy discountStrategy = new GenderDiscountStrategy(Gender.Female, 0.2m);

            ICanDiscountStrategy       canDiscountStrategy = new HappyHoursCanDiscountStrategy(TimeSpan.Parse("09:00"), TimeSpan.Parse("16:30"));
            ICalculateDiscountStrategy calculateDiscount   = new FixedDiscountStrategy(10m);

            DiscountOrderCalculator2 calculator = new DiscountOrderCalculator2(canDiscountStrategy, calculateDiscount);

            // HappyHoursOrderCalculator calculator = new HappyHoursOrderCalculator();
            decimal discount = calculator.CalculateDiscount(order);

            Console.WriteLine($"Original amount: {order.Amount:C2} Discount: {discount:C2}");
        }
        private static void PromotionTest()
        {
            ICanDiscountStrategy       canDiscountStrategy       = new HappyHoursCanDiscountStrategy(TimeSpan.Parse("09:00"), TimeSpan.Parse("16:00"));
            ICalculateDiscountStrategy calculateDiscountStrategy = new PercentageCalculateDiscountStrategy(0.2m);

            Promotion promotion = new Promotion
            {
                Id   = Guid.NewGuid(),
                Name = "Happy Hours 2020",
                From = DateTime.Parse("2020-01-01"),
                To   = DateTime.Parse("2020-12-31"),
                CanDiscountStrategy       = canDiscountStrategy,
                CalculateDiscountStrategy = calculateDiscountStrategy
            };

            Customer customer = new Customer("Anna", "Kowalska");
            Order    order    = CreateOrder(customer);

            order.Promotion = promotion;
        }