Exemplo n.º 1
0
        public void DiscountForEmptyCart()
        {
            var cart = CommonInstansesCreator.GetCart();

            var discount = new CartDiscount(cart, 50);

            Assert.Equal(0, discount.GetCost());
        }
Exemplo n.º 2
0
        public void ProductJustAddedToCart_WrongItemSelection()
        {
            var commandReciever = CommonInstansesCreator.GetOutputReciever();
            var listMgrReciever = CommonInstansesCreator.GetOutputReciever();

            listMgrReciever.GetIntResponses.Enqueue(-1);

            var command = GetCommand(commandReciever, listMgrReciever);

            command.Execute();

            Assert.Equal(new [] { "Wrong index of product. Try to choose other." }, commandReciever.ErrorWrites.ToArray());
        }
Exemplo n.º 3
0
        public void DiscountWorks()
        {
            var cart = CommonInstansesCreator.GetCart();
            var productRepository = CommonInstansesCreator.GetProductRepo();
            var product           = productRepository.FirstOrDefault();

            var item = new CartItem {
                Count = 2, Product = product
            };

            cart.AddProduct(new ProductDiscount(item, 50));

            Assert.Equal(product.Cost, cart.GetCost());
        }
Exemplo n.º 4
0
 private IConsoleCommand GetCommand(
     IOutputReciever commandOutputReciever,
     IOutputReciever listManagerOutputReciever,
     IProductRepository productRepository = null,
     ICartService cartService             = null
     )
 {
     return(new AddToCartConsoleCommand(
                productRepository ?? CommonInstansesCreator.GetProductRepo(),
                commandOutputReciever,
                cartService ?? CommonInstansesCreator.GetCartService(),
                CommonInstansesCreator.GetOutputListManager <Product>(listManagerOutputReciever)
                ));
 }
Exemplo n.º 5
0
        public void ProductJustAddedToCart()
        {
            var commandReciever = CommonInstansesCreator.GetOutputReciever();
            var listMgrReciever = CommonInstansesCreator.GetOutputReciever();

            listMgrReciever.GetIntResponses.Enqueue(0);

            var productRepository = CommonInstansesCreator.GetProductRepo();
            var cartService       = CommonInstansesCreator.GetCartService();

            var command = GetCommand(commandReciever, listMgrReciever, productRepository, cartService);

            command.Execute();

            var item = productRepository.FirstOrDefault() ?? throw new NullReferenceException();

            Assert.Equal(new [] { item }, cartService.GetCartItems().Select(cartItem => cartItem.Product));
            Assert.Equal(new [] { 1U }, cartService.GetCartItems().Select(cartItem => cartItem.Count));
        }
Exemplo n.º 6
0
        public void CommandTitleSet()
        {
            var cmd = GetCommand(CommonInstansesCreator.GetOutputReciever(), CommonInstansesCreator.GetOutputReciever());

            Assert.Equal("Add to cart.", cmd.Title);
        }