예제 #1
0
        public void FailOnPrecondition()
        {
            var discount = @"FOR BASKET WITH nonExistingProduct
                             APPLY 10% DISCOUNT TO jeans
                             APPLY 50% DISCOUNT TO jacket";

            var basket = new Basket(new List <Product>
            {
                new Product("tshirt", 50),
                new Product("jeans", 100),
                new Product("jacket", 200)
            });

            var calculator = new Calculator();

            Assert.Throws <InvalidOperationException>(() => calculator.ApplyDiscount(basket, discount));
        }
예제 #2
0
        public void ApplyDiscountToJeansOnly()
        {
            var discount = "APPLY 10% DISCOUNT TO jeans";
            var basket   = new Basket(new List <Product>
            {
                new Product("tshirt", 50),
                new Product("jeans", 100),
                new Product("jacket", 200)
            });

            var calculator = new Calculator();

            calculator.ApplyDiscount(basket, discount);

            Assert.Equal(350, basket.OriginalPrice);
            Assert.Equal(10, basket.Discount);
            Assert.Equal(340, basket.TotalPrice);
        }
예제 #3
0
        public void ApplyComplexDiscountSuccessfullyWithPrecondition()
        {
            var discount = @"FOR BASKET WITH tshirt
                             APPLY 10% DISCOUNT TO jeans
                             APPLY 50% DISCOUNT TO jacket";
            var basket   = new Basket(new List <Product>
            {
                new Product("tshirt", 50),
                new Product("jeans", 100),
                new Product("jacket", 200)
            });

            var calculator = new Calculator();

            calculator.ApplyDiscount(basket, discount);

            Assert.Equal(350, basket.OriginalPrice);
            Assert.Equal(10 + 100, basket.Discount);
            Assert.Equal(240, basket.TotalPrice);
        }