public void HalfPriceDiscount_CalculateAppliedDiscount_WithQuantity_2OrMore()
        {
            // Arrange
            var percentageDiscount = new HalfPriceDiscount(new ProductQuantity
            {
                Product = new Product
                {
                    ProductId = 2,
                    Name      = "Beans"
                },
                Quantity = 2
            },
                                                           new DiscountedProduct()
            {
                ProductId = 3,
                Name      = "Bread"
            });

            // Act
            var result = percentageDiscount.DiscountsApplicable(ProductQuantityHelper.CreateProducts()).ToArray();

            // Assert
            Assert.AreEqual(result.Any(), true);
            Assert.AreEqual(result[0].Type, DiscountType.HalfPrice);
            Assert.AreEqual(result[0].Amount, 0.40m);
            Assert.AreEqual(result[0].Text, "Bread 50% OFF: - 40p");
        }
        public void ShoppingBasket_CheckCalculateTotalPrice_WithNoDiscounts()
        {
            // Arrange
            var shoppingBasket = new ShoppingBasket(new List <IDiscount>());

            shoppingBasket.AddProducts(ProductQuantityHelper.CreateProducts());

            // Act
            var result = shoppingBasket.SubTotal - shoppingBasket.GetBasketDiscounts().Sum(item => item.Amount);

            // Assert
            Assert.AreEqual(result, 3.23m);
        }
        public void ShoppingBasket_AddProducts_CheckProductsCount(int productsToCreate)
        {
            // Arrange
            var shoppingBasket = new ShoppingBasket(new List <IDiscount>());

            shoppingBasket.AddProducts(ProductQuantityHelper.CreateProducts(productsToCreate));

            // Act
            var result = shoppingBasket.ProductCount;

            // Assert
            Assert.AreEqual(result, productsToCreate);
        }
        public void PercentageDiscount_CalculateAppliedDiscount_With50PercentDiscount()
        {
            // Arrange
            var percentageDiscount = new PercentageDiscount(DiscountHelper.CreateDiscountedProducts(), 0.50m);

            // Act
            var result = percentageDiscount.DiscountsApplicable(ProductQuantityHelper.CreateProducts()).ToArray();

            // Assert
            Assert.AreEqual(result.Any(), true);
            Assert.AreEqual(result[0].Type, DiscountType.Percentage);
            Assert.AreEqual(result[0].Amount, 0.16m);
            Assert.AreEqual(result[0].Text, "Apples 50% OFF: - 16p");
        }
        public void PercentageDiscount_NoDiscountApplied_With10PercentDiscount()
        {
            // Arrange
            var percentageDiscount = new PercentageDiscount(new DiscountedProduct
            {
                ProductId = 4,
                Name      = "Milk"
            }, 0.10m);

            // Act
            var result = percentageDiscount.DiscountsApplicable(ProductQuantityHelper.CreateProducts()).ToArray();

            // Assert
            Assert.AreEqual(result.Any(), false);
        }
        public void ShoppingBasket_CheckCalculateTotalPrice_WithHalfPriceDiscount()
        {
            // Arrange
            var halfPriceDiscount = new Mock <IDiscount>();

            halfPriceDiscount.Setup(mock => mock.DiscountsApplicable(It.IsAny <IEnumerable <ProductQuantity> >()))
            .Returns(DiscountHelper.CreateHalfPriceAppliedDiscount);

            var shoppingBasket = new ShoppingBasket(new List <IDiscount> {
                halfPriceDiscount.Object
            });

            shoppingBasket.AddProducts(ProductQuantityHelper.CreateProducts());

            // Act
            var discountsTotal = shoppingBasket.GetBasketDiscounts().Sum(item => item.Amount);
            var result         = shoppingBasket.SubTotal - discountsTotal;

            // Assert
            Assert.AreEqual(result, 2.83m);
        }
        public void ShoppingBasket_GetBasketDiscounts_WithNoDiscountApplied()
        {
            // Arrange
            var discounts = new Mock <IDiscount>();

            discounts.Setup(mock => mock.DiscountsApplicable(It.IsAny <IEnumerable <ProductQuantity> >()))
            .Returns(DiscountHelper.CreateNoDiscountApplied);

            var shoppingBasket = new ShoppingBasket(new List <IDiscount> {
                discounts.Object
            });

            shoppingBasket.AddProducts(ProductQuantityHelper.CreateProducts());

            // Act
            var result = shoppingBasket.GetBasketDiscounts().ToArray();

            // Assert
            Assert.AreEqual(result.Any(), true);
            Assert.AreEqual(result[0].Type, DiscountType.None);
            Assert.AreEqual(result[0].Amount, 0.00m);
            Assert.AreEqual(result[0].Text, "(No offers available)");
        }
        public void HalfPriceDiscount_NoDiscountApplied_WithQuantity_20rMore()
        {
            // Arrange
            var percentageDiscount = new HalfPriceDiscount(new ProductQuantity
            {
                Product = new Product
                {
                    ProductId = 2,
                    Name      = "Beans"
                },
                Quantity = 2
            },
                                                           new DiscountedProduct()
            {
                ProductId = 4,
                Name      = "Milk"
            });

            // Act
            var result = percentageDiscount.DiscountsApplicable(ProductQuantityHelper.CreateProducts()).ToArray();

            // Assert
            Assert.AreEqual(result.Any(), false);
        }