Esempio n. 1
0
 public void Serialize()
 {
     CartManager manager = new CartManager(new CookieUserDataRepository());
     manager.AddProduct(1);
     manager.AddProduct(2);
     List<int> current = manager.GetProducts();
 }
Esempio n. 2
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);
        }
Esempio n. 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]);
        }
Esempio n. 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));
        }
        private ICartManager GetCartManager(IProductRepository productRepository, IUserRepository userRepository)
        {
            ICartRepository     cartRepository     = new StubCartRepository();
            ICartItemRepository cartItemRepository = new StubCartItemRepository();
            IPointSystemConfigurationRepository configurationRepository = new StubPointSystemConfigurationRepository();

            configurationRepository.AddEntity(new PointSystemConfiguration()
            {
                PropertyName = ESportUtils.LOYALTY_PROPERTY_NAME, PropertyValue = 100
            });
            ICartManager cartManager = new CartManager(cartRepository, cartItemRepository, productRepository, userRepository, configurationRepository);
            CartRequest  cartRequest = GetCartRequest();
            Cart         currentCart = cartManager.AddProduct(cartRequest);

            itemTest = currentCart.Items.Where(item => item.Product.ProductId.Equals(cartRequest.ProductId)).First();
            cartManager.ConfirmCart(cartRequest);
            return(cartManager);
        }
Esempio n. 6
0
        public void ShouldReturnTheNewCartAfterAddID()
        {
            // Arrange
            IReadFromBrowser read   = new FakeReadCookie();
            CartManager      cart   = new CartManager(read);
            List <long>      listID = new List <long>()
            {
                23, 45, 32, 12, 2, 3
            };
            ShoppingCart shoppingCart = new ShoppingCart()
            {
                ProductIDs = listID, UserID = 3
            };

            //Act

            var currentCart = cart.AddProduct(90, shoppingCart);

            //Assert

            Assert.Contains <long>(90, currentCart.ProductIDs);
        }
        public IActionResult AddToCart(int id)
        {
            CartManager.AddProduct(id, _context);

            return(PartialView("_CartPartial"));
        }