Exemple #1
0
        public void TenPercentDiscount()
        {
            // ARRANGE
            SupermarketCatalog catalog = new FakeCatalog();
            var toothbrush             = new Product("toothbrush", ProductUnit.Each);

            catalog.AddProduct(toothbrush, 0.99);
            var apples = new Product("apples", ProductUnit.Kilo);

            catalog.AddProduct(apples, 1.99);

            var cart = new ShoppingCart();

            cart.AddItemQuantity(apples, 2.5);

            var teller = new Teller(catalog);

            teller.AddSpecialOffer(SpecialOfferType.TenPercentDiscount, toothbrush, 10.0);

            // ACT
            var receipt = teller.ChecksOutArticlesFrom(cart);

            // ASSERT
            Assert.Equal(4.975, receipt.GetTotalPrice());
            Assert.Equal(new List <Discount>(), receipt.GetDiscounts());
            Assert.Single(receipt.GetItems());
            var receiptItem = receipt.GetItems()[0];

            Assert.Equal(apples, receiptItem.Product);
            Assert.Equal(1.99, receiptItem.Price);
            Assert.Equal(2.5 * 1.99, receiptItem.TotalPrice);
            Assert.Equal(2.5, receiptItem.Quantity);
        }
        private static Teller CreateTeller()
        {
            SupermarketCatalog catalog = new FakeCatalog();

            catalog.AddProduct(Toothbrush, 0.99);
            catalog.AddProduct(Apples, 1.99);

            return(new Teller(catalog));
        }
Exemple #3
0
        public void ProductIsNotInCatalog_ReturnKeyNotFoundException()
        {
            IShoppingCatalog Catalog = new FakeCatalog();

            Catalog.AddProduct(RubberGloves, 399);
            Catalog.AddProduct(Talc, 399);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(Stethoscope, 1));

            var order = new Order(Catalog);

            Assert.Throws <KeyNotFoundException>(() => order.ChecksOutGoods(cart));
        }
Exemple #4
0
        public void GetTotalCartPrice_IfOfferIsNotApplied_OnAllProduct_ReturnAmountWithUnDiscountedPrice()
        {
            double           expectedValue = 458.90;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(RubberGloves, 59.90);
            Catalog.AddProduct(Stethoscope, 399);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(RubberGloves, 1));
            cart.AddLine(new OrderLine(Stethoscope, 1));

            var order   = new Order(Catalog);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #5
0
        public void OrderLineIsEmpty_ReturnArgumentNullException()
        {
            IShoppingCatalog Catalog = new FakeCatalog();

            Catalog.AddProduct(RubberGloves, 399);

            ShoppingCart cart = new ShoppingCart();

            var order = new Order(Catalog);

            Assert.Throws <ArgumentNullException>(() => order.ChecksOutGoods(cart));
        }
Exemple #6
0
        public void GetTotalCartPrice_IfOfferOnStethoscope_ReturnAmountWithDiscountPrice()
        {
            double           expectedValue = 1179.745;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(Talc, 19.54);
            Catalog.AddProduct(Stethoscope, 19.54);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(Stethoscope, 3));
            cart.AddLine(new OrderLine(Talc, 9.25));

            var order = new Order(Catalog);

            order.AddSpecialOffer(SpecialOfferType.ThreeForAmount, Stethoscope);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #7
0
        public void GetTotalCartPrice_IfOfferOnRubberGloves_ReturnAmountWithDiscountPrice()
        {
            double           expectedValue = 315.2;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(RubberGloves, 59.90);
            Catalog.AddProduct(Talc, 19.54);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(RubberGloves, 3));
            cart.AddLine(new OrderLine(Talc, 10));

            var order = new Order(Catalog);

            order.AddSpecialOffer(SpecialOfferType.ThreeForTwo, RubberGloves);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #8
0
        public void GetTotalCartPrice_IfOfferIsApplied_SingleProduct_ReturnAmountWithDiscountedPriceForOneProdcuctInCart()
        {
            double           expectedValue = 2177.70;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(RubberGloves, 59.90);
            Catalog.AddProduct(Stethoscope, 399);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(RubberGloves, 3));
            cart.AddLine(new OrderLine(Stethoscope, 6));

            var order = new Order(Catalog);

            order.AddSpecialOffer(SpecialOfferType.ThreeForAmount, Stethoscope);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #9
0
        public void GetTotalCartPrice_NotInOffer_ForTalc_ReturnAmountWihtUndiscountPrice(double weight, double expectedValue)
        {
            IShoppingCatalog Catalog = new FakeCatalog();

            Catalog.AddProduct(Talc, 19.54);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(Talc, weight));

            var order   = new Order(Catalog);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #10
0
        public void GetTotalCartPrice_IfOfferIsNotAppliedOnValidQuantity_OfStethoscope_ReturnAmountWithUnDiscountedPrice()
        {
            double           expectedValue = 1197;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(Stethoscope, 399);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(Stethoscope, 3));

            var order   = new Order(Catalog);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #11
0
        public void GetTotalCartPrice_IfOfferNotValidOnQunatity_ForOnePairRubberGloves_ReturnAmountWithDicountedPrice()
        {
            double           expectedValue = 59.90;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(RubberGloves, 59.90);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(RubberGloves, 1));

            var order   = new Order(Catalog);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #12
0
        public void GetTotalCartPrice_IfOfferIsValid_ForStethoscope_ReturnAmountWithDiscountedPrice(int quantity, double expectedValue)
        {
            IShoppingCatalog Catalog = new FakeCatalog();

            Catalog.AddProduct(Stethoscope, 399);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(Stethoscope, quantity));

            var order = new Order(Catalog);

            order.AddSpecialOffer(SpecialOfferType.ThreeForAmount, Stethoscope);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #13
0
        public void GetTotalCartPrice_OfferNotValidOnProduct_ReturnAmountWithUnDiscountedPrice(SpecialOfferType specialOfferType)
        {
            double           expectedValue = 29.31;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(Talc, 19.54);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(Talc, 1.5));

            var order = new Order(Catalog);

            order.AddSpecialOffer(specialOfferType, Talc);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #14
0
        public void GetTotalCartPrice_IfInValidProductOffer_Stethoscope_ReturnAmountWithUnDiscountedPrice()
        {
            double           expectedValue = 1197;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(Stethoscope, 399);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(Stethoscope, 3));

            var order = new Order(Catalog);

            order.AddSpecialOffer(SpecialOfferType.ThreeForAmount, RubberGloves);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }
Exemple #15
0
        public void GetTotalCartPrice_WithValidOffer_And_SeveralOrderLineOfSameCode_ForRubberGloves_ReturnAmountWithDiscountedPrice()
        {
            double           expectedValue = 119.80;
            IShoppingCatalog Catalog       = new FakeCatalog();

            Catalog.AddProduct(RubberGloves, 59.90);

            ShoppingCart cart = new ShoppingCart();

            cart.AddLine(new OrderLine(RubberGloves, 1));
            cart.AddLine(new OrderLine(RubberGloves, 1));
            cart.AddLine(new OrderLine(RubberGloves, 1));

            var order = new Order(Catalog);

            order.AddSpecialOffer(SpecialOfferType.ThreeForTwo, RubberGloves);
            var receipt = order.ChecksOutGoods(cart);

            double actaulValue = receipt.GetTotalPrice();

            Assert.AreEqual(expectedValue, actaulValue);
        }