예제 #1
0
        public void Calculate2DiscountTest()
        {
            // Arrange
            ICanDiscountStrategy canDiscountStrategy = new HappyHoursCanDiscountStrategy(
                TimeSpan.Parse("12:30"),
                TimeSpan.Parse("14:00"));

            IDiscountStrategy discountStrategy = new FixedDiscountStrategy(5);

            OrderCalculator orderCalculator = new OrderCalculator(canDiscountStrategy, discountStrategy);

            Order order = new Order("ZAM 001/2018", new Customer("M", "S"));

            order.CreateDate = DateTime.Parse("2018-06-19 12:30");

            Product product1 = new Product("Monitor", 1000);

            order.Details.Add(new OrderDetail(product1, 10));

            // Acts
            decimal discount = orderCalculator.CalculateDiscount(order);

            // Asserts
            Assert.AreEqual(5, discount);
        }
        public void CanDiscount_IsHappyHours_ReturnsCanDiscount(TimeSpan from, TimeSpan to, DateTime orderDate, bool expected)
        {
            Order order = new Order {
                OrderedDate = orderDate
            };

            // Arrange
            ICanDiscountStrategy canDiscount = new HappyHoursCanDiscountStrategy(from, to);

            // Act
            var result = canDiscount.CanDiscount(order);

            // Assets
            result.Should().Be(expected);
        }
예제 #3
0
        private static void Test()
        {
            Console.WriteLine("Branch aszatkowski");

            Console.WriteLine("Hello Marcin");
            byte x = 255;

            checked
            {
                x++;
                x++;
            }

            Console.WriteLine(x);

            // ICustomerRepository customerRepository = new FakeCustomerRepository();

            // var customers = customerRepository.GetByPesel("64645645");

            Product product = new Product
            {
                Name      = "Keyboard",
                Color     = "Black",
                UnitPrice = 1000,
            };

            Order order = new Order
            {
                NumberOrder = "ZAM 001",
            };

            order.Add(product);

            ICanDiscountStrategy canDiscountStrategy = new HappyHoursCanDiscountStrategy(
                from: TimeSpan.Parse("09:30"),
                to: TimeSpan.Parse("17:00"),
                minimumAmount: 100m
                );

            ICalculateDiscountStrategy calculateDiscountStrategy = new FixedCalculateDiscountStrategy(10);

            IDiscountCalculator orderCalculator
                = new DiscountCalculator(canDiscountStrategy, calculateDiscountStrategy);

            decimal discount = orderCalculator.CalculateDiscount(order);

            Console.WriteLine(discount);
        }