Ejemplo n.º 1
0
        public void DadoQueOUsuarioAdcionouProdutoNoCarrinho(string quantidade)
        {
            var count = 0;

            switch (quantidade)
            {
            case "Um produto":
                productController.AddToCart();
                cartController.VerifyCart("1");
                break;

            case "Três produtos":
                while (count < 3)
                {
                    productController.AddToCart();
                    count++;
                }
                cartController.VerifyCart("3");
                break;
            }
        }
Ejemplo n.º 2
0
        public void ShouldDisplayErrorAddingToCart()
        {
            //service method mocked to return false
            _userService.Setup(service => service.AddToCart(productID)).Returns(false);
            _messageService.Setup(service => service.ItemAddedSuccess()).Verifiable();
            _messageService.Setup(service => service.ItemAddedError()).Verifiable();
            ProductController controller = new ProductController(productService: null, userService: _userService.Object, messageViewService: _messageService.Object);
            var result = controller.AddToCart(1);

            //Assert.IsType<Boolean>(result);
            _messageService.Verify(service => service.ItemAddedError(), Times.Once());
            _messageService.Verify(service => service.ItemAddedSuccess(), Times.Never());
            //verifies that the user gets redirected to the index action
            var actionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", actionResult.ActionName);
        }