Exemple #1
0
        public void Can_Remove_From_Cart()
        {
            var productsArray = products.Products.ToArray();
            Cart cart = new Cart();
            cart.AddItem(productsArray[0], 1);
            cart.AddItem(productsArray[1], 1);
            cart.AddItem(productsArray[2], 1);
            CartController target = new CartController(products, orderProcessor);

            RedirectToRouteResult result = (RedirectToRouteResult)target.RemoveFromCart(cart, productsArray[1].ProductID, "testUrl");
            Assert.AreEqual(result.RouteValues["returnUrl"], "testUrl");
            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(cart.Lines.ToArray()[0].Product, productsArray[0]);
            Assert.AreEqual(cart.Lines.ToArray()[1].Product, productsArray[2]);
        }
        public void Deleting_Product_To_Cart_Goes_To_Cart_Screen()
        {
            //Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(products.AsQueryable());
            CartController target = new CartController(mock.Object, null); // TODO: Initialize to an appropriate value
            Cart cart = new Cart(); // TODO: Initialize to an appropriate value

            //Act
            RedirectToRouteResult result = target.RemoveFromCart(cart, 2, "myUrl");

            //Assert
            Assert.AreEqual("Index", result.RouteValues["Action"]);
            Assert.AreEqual("myUrl", result.RouteValues["returnUrl"]);
        }
        public void Can_Delete_Product_From_Cart()
        {
            //Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(products.AsQueryable());
            CartController target = new CartController(mock.Object, null); // TODO: Initialize to an appropriate value
            Cart cart = new Cart(); // TODO: Initialize to an appropriate value
            target.AddToCart(cart, 1, "myUrl");
            //Act
            RedirectToRouteResult result = target.RemoveFromCart(cart, 1, "myUrl");

            //Assert
            Assert.AreSame(cart, cart);
            Assert.AreEqual(0, cart.Lines.ToArray().Length);
        }
Exemple #4
0
        public void Can_Remove_From_Cart()
        {
            Product p1 = new Product { ProductID = 1, Name = "P1", Category = "Apples" };
            Product p2 = new Product { ProductID = 2, Name = "P2", Category = "Pear" };
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] { p1, p2
            }.AsQueryable());

            Cart cart = new Cart();
            cart.AddItem(p1, 1);
            cart.AddItem(p2, 3);
            cart.AddItem(p1, 2);

            CartController target = new CartController(mock.Object, null);

            target.RemoveFromCart(cart, 1, null);

            Assert.AreEqual(cart.Lines.Count(), 1);
            Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 2);
        }
        public void Can_Remove_Product_From_Cart()
        {
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product { ProductId = 123 }
                , new Product { ProductId = 456 }
                );

            var cartController = new CartController(mockProductsRepository, null);
            var cart = new Cart();

            if (mockProductsRepository.Products != null)
                foreach (var product in mockProductsRepository.Products)
                    cartController.AddToCart(cart, product.ProductId, null);

            cartController.RemoveFromCart(cart, 456, null);

            cart.Lines.Count.ShouldEqual(1);
            cart.Lines[0].Product.ProductId.ShouldEqual(123);
        }
Exemple #6
0
        public void Can_Remove_Product_From_Cart()
        {
            // Arrange: Given a repository with some products...
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product { ProductID = 1 }
            );
            var cartController = new CartController(mockProductsRepository,null);
            var cart = new Cart();

            // Act: When a user adds a product to their cart...
            cartController.AddToCart(cart, 1, null);
            var result = cartController.RemoveFromCart(cart, 1, "deleteReturnUrl");

            // Assert: Then the user is redirected to the Cart Index screen
            result.ShouldBeRedirectionTo(new
            {
                action = "Index",
                returnUrl = "deleteReturnUrl"
            });
        }