Beispiel #1
0
        public void AddDiscounts()
        {
            var rp = new TestReceiptPrinter();
            var dp = new DiscountsProvider();
            var m  = new CartManager(new Cart(), rp, dp);

            var productDiscount = dp.GetProductsDiscounts().First();
            var cartDiscount    = dp.GetCartDiscounts().First();

            m.AddDiscount(productDiscount.Key);
            m.AddDiscount(cartDiscount.Key);

            var c1 = TestProducts.Cars.First();
            var c2 = TestProducts.Cars.Skip(1).First();

            m.AddProduct(c1);
            m.AddProduct(c2);

            m.PrintReceipt();
            var state = rp.CartState;

            Assert.Equal(1, state.ProductDiscounts.Count);
            Assert.Equal(c1, state.ProductDiscounts.First().Key);
            Assert.Equal(productDiscount.Value.Value, state.ProductDiscounts.First().Value.PercentValue);

            Assert.Equal(1, state.CartDiscounts.Count);
            Assert.Equal(cartDiscount.Value, state.CartDiscounts.First().PercentValue);
        }
Beispiel #2
0
        public void AddNonExistingDiscount()
        {
            var rp = new TestReceiptPrinter();
            var dp = new DiscountsProvider();
            var m  = new CartManager(new Cart(), rp, dp);

            Assert.Throws <DiscountNotFoundException>(() => m.AddDiscount("NON_EXISTING_CODE"));
        }
Beispiel #3
0
        public void AddProducts()
        {
            var rp = new TestReceiptPrinter();
            var m  = new CartManager(new Cart(), rp, new DiscountsProvider());
            var c1 = TestProducts.Cars.First();
            var c2 = TestProducts.Cars.Skip(1).First();

            m.AddProduct(c1);
            m.AddProduct(c1);
            m.AddProduct(c2);

            m.PrintReceipt();
            var state = rp.CartState;

            Assert.Equal(2, state.Products.Count);
            Assert.Equal(2, state.Products[c1]);
        }
Beispiel #4
0
        public void RemoveMoreProductsThanExistsInCartOfAKind()
        {
            var rp = new TestReceiptPrinter();
            var m  = new CartManager(new Cart(), rp, new DiscountsProvider());
            var c1 = TestProducts.Cars.First();
            var c2 = TestProducts.Cars.Skip(1).First();

            m.AddProduct(c1);
            m.AddProduct(c1);
            m.AddProduct(c1);
            m.AddProduct(c2);

            m.RemoveProduct(c1, 5);

            m.PrintReceipt();
            var state = rp.CartState;

            Assert.Equal(1, state.Products.Count);
            Assert.False(state.Products.ContainsKey(c1));
        }