Ejemplo n.º 1
0
        public void Given_Cart_When_DiscountedProductFoundBananas_And_AssociatedProductsFound_Then_ApplyCorrectDiscount(
            int bananasCount, int orangesCount, decimal expectedDiscount, string expectedDescription)
        {
            // Arrange
            var prerequisite = new RequiredProductPerDiscount("Oranges", 10);

            var items = new List <CartItem>
            {
                new CartItem(new Product("Milk", 1.0m), 1),
                new CartItem(new Product("Tomato", 0.50m), 1),
                new CartItem(new Product("Bananas", 1.30m), bananasCount),
                new CartItem(new Product("Oranges", 1.50m), orangesCount)
            };

            var sut = new MultiBuyPercentageDiscount("Bananas", 100, prerequisite);

            // Act
            var result = sut.Apply(items);

            // Assert
            Assert.Collection(result, d =>
            {
                Assert.Equal(expectedDescription, d.Description);
                Assert.Equal(expectedDiscount, d.Amount);
            });
        }
Ejemplo n.º 2
0
        public void Given_Cart_When_NoDiscountedProductFound_Then_NoDiscountApplies()
        {
            // Arrange
            var prerequisite = new RequiredProductPerDiscount("Soup", 2);

            var items = new List <CartItem>
            {
                new CartItem(new Product("Milk", 1.0m), 1),
                new CartItem(new Product("Tomato", 0.50m), 1)
            };

            var sut = new MultiBuyPercentageDiscount("Bread", 50, prerequisite);

            // Act
            var result = sut.Apply(items);

            // Assert
            Assert.Empty(result);
        }