Esempio n. 1
0
        public void MultibuyOnlyOneRelatedProducts()
        {
            ISpecialOffer offer           = new MultibuyOffer("Beans", 2, "Soup", 1);
            var           discountProduct = offer.DetermineSpecialOffer(_products);

            Assert.IsNull(discountProduct);
        }
Esempio n. 2
0
        public void MultibuyBothRelatedProductsNotEnoughRequired()
        {
            //need two beans to get the offer, so shouldn't give an offer
            ISpecialOffer offer           = new MultibuyOffer("Beans", 2, "Eggs", 1);
            var           discountProduct = offer.DetermineSpecialOffer(_products);

            Assert.IsNull(discountProduct);
        }
Esempio n. 3
0
        public void MultibuyNoRelatedProducts()
        {
            //no products involved in the deal in the list
            ISpecialOffer offer           = new MultibuyOffer("Soup", 2, "Milk", 1);
            var           discountProduct = offer.DetermineSpecialOffer(_products);

            Assert.IsNull(discountProduct);
        }
Esempio n. 4
0
        public void MultibuyBothRelatedProductsMultipleProductsOffer()
        {
            //have two beans, can get two eggs discounted, two eggs are present so should get two eggs discounted
            var _twoBeansTwoEggs = new List <Product>()
            {
                new Product("Beans", 0.9m), new Product("Beans", 0.9m), new Product("Eggs", 0.3m), new Product("Eggs", 0.3m)
            };
            ISpecialOffer offer           = new MultibuyOffer("Beans", 2, "Eggs", 2);
            var           discountProduct = offer.DetermineSpecialOffer(_twoBeansTwoEggs);

            Assert.AreEqual <decimal>(-0.6m, discountProduct.Price);
            Assert.AreEqual("Discount on Eggs", discountProduct.ProductName);
        }
Esempio n. 5
0
        public void MultibuyBothRelatedProductsMorePresentThanOffer()
        {
            //have two beans, can get one egg discounted even though two eggs are present
            var _twoBeansTwoEggs = new List <Product>()
            {
                new Product("Beans", 0.9m), new Product("Beans", 0.9m), new Product("Eggs", 0.3m), new Product("Eggs", 0.3m)
            };
            ISpecialOffer offer           = new MultibuyOffer("Beans", 2, "Eggs", 1);
            var           discountProduct = offer.DetermineSpecialOffer(_twoBeansTwoEggs);

            Assert.AreEqual <decimal>(-0.3m, discountProduct.Price);
            Assert.AreEqual("Discount on Eggs", discountProduct.ProductName);
        }
Esempio n. 6
0
        public void MultibuyBothRelatedProductsMoreOfferThanPresent()
        {
            //have two beans, could get two eggs discounted, but only one egg is present
            //thus only one egg is discounted
            var _twoBeansOneEggs = new List <Product>()
            {
                new Product("Beans", 0.9m), new Product("Beans", 0.9m), new Product("Eggs", 0.3m)
            };
            ISpecialOffer offer           = new MultibuyOffer("Beans", 2, "Eggs", 2);
            var           discountProduct = offer.DetermineSpecialOffer(_twoBeansOneEggs);

            Assert.AreEqual <decimal>(-0.3m, discountProduct.Price);
            Assert.AreEqual("Discount on Eggs", discountProduct.ProductName);
        }
Esempio n. 7
0
        public void MultibuyNoOfferTest(int cheeseCount)
        {
            var productName  = "Cheese";
            var numberNeeded = 3;
            var offer        = new MultibuyOffer(productName, numberNeeded);

            var products = new Dictionary <Product, int>();

            products.Add(new Product("Cheese", 0.5m), cheeseCount);

            var discountedProduct = offer.DetermineSpecialOffer(products);

            Assert.IsNull(discountedProduct);
        }
Esempio n. 8
0
        public void MultibuyDetermineOfferTest(int cheeseCount, decimal expectedDiscountValue)
        {
            var productName  = "Cheese";
            var numberNeeded = 3;
            var offer        = new MultibuyOffer(productName, numberNeeded);

            var products = new Dictionary <Product, int>();

            products.Add(new Product("Cheese", 0.5m), cheeseCount);

            var expectedDiscountProduct = new Product("Cheese Multibuy", expectedDiscountValue);


            var discountedProduct = offer.DetermineSpecialOffer(products);

            Assert.AreEqual(expectedDiscountProduct, discountedProduct);
        }