예제 #1
0
        public void WhenRemovingAddedProduct_ShouldClearProductFromCartAndReturnZeroQuantity()
        {
            var productsRepository = new ProductsRepository();
            var cartRepository     = new ShoppingCartRepository();

            var cartManager = new CartCommandManager();
            var canon       = new Product("EOSR1", "Canon EOS R", 1099);

            var addCanonCommand = new AddToCartCommand(
                cartRepository,
                productsRepository,
                canon);

            var removeCanonCommand = new RemoveFromCartCommand(
                cartRepository,
                productsRepository,
                canon
                );

            cartManager.Execute(addCanonCommand);
            cartManager.Execute(addCanonCommand);
            cartManager.Execute(removeCanonCommand);
            cartManager.Execute(removeCanonCommand);
            cartManager.Execute(removeCanonCommand);

            cartRepository.Get("EOSR1").Quantity.Should().Be(0);
        }
예제 #2
0
        public void WhenAddingNewProductToCart_ShouldIncreaseStockInCartRepository()
        {
            var productsRepository = new ProductsRepository();
            var cartRepository     = new ShoppingCartRepository();

            var cartManager = new CartCommandManager();
            var canon       = new Product("EOSR1", "Canon EOS R", 1099);

            var addCanonCommand = new AddToCartCommand(
                cartRepository,
                productsRepository,
                canon);

            cartManager.Execute(addCanonCommand);
            cartManager.Execute(addCanonCommand);

            cartRepository.Get("EOSR1").Quantity.Should().Be(2);
        }