当前位置: 首页>>代码示例>>C#>>正文


C# CartController.RemoveFromCart方法代码示例

本文整理汇总了C#中SportsStore.WebUI.Controllers.CartController.RemoveFromCart方法的典型用法代码示例。如果您正苦于以下问题:C# CartController.RemoveFromCart方法的具体用法?C# CartController.RemoveFromCart怎么用?C# CartController.RemoveFromCart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SportsStore.WebUI.Controllers.CartController的用法示例。


在下文中一共展示了CartController.RemoveFromCart方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Can_Remove_From_Cart

        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]);
        }
开发者ID:Shiloff,项目名称:SportsStore,代码行数:15,代码来源:CartTests.cs

示例2: Deleting_Product_To_Cart_Goes_To_Cart_Screen

        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"]);
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:15,代码来源:CartControllerTest.cs

示例3: Can_Delete_Product_From_Cart

        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);
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:15,代码来源:CartControllerTest.cs

示例4: Can_Remove_From_Cart

        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);
        }
开发者ID:gkudel,项目名称:SportsStore,代码行数:20,代码来源:CartTest.cs

示例5: Can_Remove_Product_From_Cart

        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);
        }
开发者ID:hcabnettek,项目名称:SportsStore,代码行数:19,代码来源:ShoppingCart.cs

示例6: Can_Remove_Product_From_Cart

        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"
            });
        }
开发者ID:astrateg,项目名称:SportsStore,代码行数:20,代码来源:ShoppingCart.cs


注:本文中的SportsStore.WebUI.Controllers.CartController.RemoveFromCart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。