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


C# CartController.AddToCart方法代码示例

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


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

示例1: Adding_Product_To_Cart_Goes_To_Cart_Screen

        public void Adding_Product_To_Cart_Goes_To_Cart_Screen()
        {
            // Arrange
            // - Create the mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product { ProductID = 1, Name = "P1", Category = "Apples" }
            }.AsQueryable());

            // Arrange
            // - Create a Cart
            Cart cart = new Cart();

            // Arrange
            // - Create the controller
            CartController target = new CartController(mock.Object, null);

            // Act
            // - Add a product to the cart
            RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl");

            // Assert
            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl");
        }
开发者ID:Zanion,项目名称:SportsStore,代码行数:25,代码来源:CartTests.cs

示例2: Adding_product_goes_to_cart_screen

        public void Adding_product_goes_to_cart_screen()
        {
            var cart = new Cart();
            var controller = new CartController(CreateRepositoryMock().Object, null);

            var result = controller.AddToCart(cart, 2, "my url");

            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(result.RouteValues["returnUrl"], "my url");
        }
开发者ID:vcaraulean,项目名称:Pro-ASP-NET-MVC-SportsStore,代码行数:10,代码来源:CartControllerTests.cs

示例3: Adding_Products_To_Cart_Goes_To_Cart_Screen

        public void Adding_Products_To_Cart_Goes_To_Cart_Screen()
        {
            var productsArray = products.Products.ToArray();
            Cart cart = new Cart();
            CartController target = new CartController(products, orderProcessor);

            RedirectToRouteResult result = target.AddToCart(cart, 1, "testUrl");
            Assert.AreEqual(result.RouteValues["returnUrl"], "testUrl");
            Assert.AreEqual(result.RouteValues["action"], "Index");
        }
开发者ID:Shiloff,项目名称:SportsStore,代码行数:10,代码来源:CartTests.cs

示例4: Can_Add_To_Cart

        public void Can_Add_To_Cart()
        {
            var productsArray = products.Products.ToArray();
            Cart cart = new Cart();
            CartController target = new CartController(products, orderProcessor);

            target.AddToCart(cart, 1, "testUrl");

            Assert.AreEqual(cart.Lines.Count(), 1);
            Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1);
        }
开发者ID:Shiloff,项目名称:SportsStore,代码行数:11,代码来源:CartTests.cs

示例5: After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen

        public void After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen()
        {
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product { ProductId = 1 }

                );

            var cartController = new CartController(mockProductsRepository, null);
            var result = cartController.AddToCart(new Cart(), 1, "someReturnUrl");

            result.ShouldBeRedirectionTo(new {action = "Index", returnUrl = "someReturnUrl"});
        }
开发者ID:hcabnettek,项目名称:SportsStore,代码行数:12,代码来源:ShoppingCart.cs

示例6: Can_add_to_cart

        public void Can_add_to_cart()
        {
            var mockRepository = CreateRepositoryMock();

            var controller = new CartController(mockRepository.Object, null);
            var cart = new Cart();

            controller.AddToCart(cart, 1, null);

            Assert.AreEqual(1, cart.Lines.Count());
            Assert.AreEqual(cart.Lines.ElementAt(0).Product.ProductID, 1);
        }
开发者ID:vcaraulean,项目名称:Pro-ASP-NET-MVC-SportsStore,代码行数:12,代码来源:CartControllerTests.cs

示例7: Adding_Prod_To_Cart_Goes_To_Cart_Screen

        public void Adding_Prod_To_Cart_Goes_To_Cart_Screen()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]{
                new Product{ProductID = 1, Name = "P1",Category = "Apples"},
            }.AsQueryable());
            Cart cart = new Cart();
            CartController target = new CartController(mock.Object, null);

            RedirectToRouteResult res = target.AddToCart(cart, 2, "MyUrl");

            Assert.AreEqual(res.RouteValues["action"], "Index");
            Assert.AreEqual(res.RouteValues["returnUrl"], "MyUrl");
        }
开发者ID:Karoliner,项目名称:sports_store,代码行数:14,代码来源:UnitTest2.cs

示例8: Can_Add_To_Cart

        public void Can_Add_To_Cart()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]{
                new Product{ProductID = 1, Name = "P1",Category = "Apples"},
            }.AsQueryable());
            Cart cart = new Cart();
            CartController target = new CartController(mock.Object, null);

            target.AddToCart(cart, 1, null);

            Assert.AreEqual(cart.Lines.Count(), 1);
            Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1);
        }
开发者ID:Karoliner,项目名称:sports_store,代码行数:14,代码来源:UnitTest2.cs

示例9: AddingProductToCartGoesToCartScreen

        public void AddingProductToCartGoesToCartScreen()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new[]
            {new Product {ProductID = 1, Name = "P1", Category = "Apples"}}
                );
            Cart cart = new Cart();
            CartController target = new CartController(mock.Object, null);

            var result = target.AddToCart(cart, 1, "myUrl");

            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl");
        }
开发者ID:brainiacOnly,项目名称:SportsStore,代码行数:14,代码来源:CartTests.cs

示例10: AddingProductToCartScreen

        public void AddingProductToCartScreen()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product(){Id = 1, Name = "P1", Category = "Jabłka"}
            }.AsQueryable());
            Cart cart = new Cart();
            CartController controller = new CartController(mock.Object, null);

            RedirectToRouteResult result = controller.AddToCart(cart, 2, "myUrl");

            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl");
        }
开发者ID:MichalZawadzki,项目名称:SportsStore,代码行数:15,代码来源:CartTests.cs

示例11: Can_Add_Product_To_Cart

        public void Can_Add_Product_To_Cart()
        {
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product {ProductId = 123}
                , new Product {ProductId = 456}
                );

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

            cartController.AddToCart(cart, 456, null);

            cart.Lines.Count.ShouldEqual(1);
            cart.Lines[0].Product.ProductId.ShouldEqual(456);
        }
开发者ID:hcabnettek,项目名称:SportsStore,代码行数:15,代码来源:ShoppingCart.cs

示例12: Adding_Product_To_Cart_Goes_To_Cart_Screen

        public void Adding_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.AddToCart(cart, 2, "myUrl");

            //Assert
            Assert.AreEqual("Index", result.RouteValues["Action"]);
            Assert.AreEqual("myUrl", result.RouteValues["returnUrl"]);
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:15,代码来源:CartControllerTest.cs

示例13: After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen

        public void After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen()
        {
            // Arrange: Given a repository with some products...
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product { ProductID = 1 }
            );
            var cartController = new CartController(mockProductsRepository, null);

            // Act: When a user adds a product to their cart...
            var result = cartController.AddToCart(new Cart(), 1, "someReturnUrl");

            // Assert: Then the user is redirected to the Cart Index screen
            result.ShouldBeRedirectionTo(new {
                action = "Index",
                returnUrl = "someReturnUrl"
            });
        }
开发者ID:astrateg,项目名称:SportsStore,代码行数:17,代码来源:ShoppingCart.cs

示例14: CanAddToCart

        public void CanAddToCart()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(x => x.Products).Returns(new Product[]
            {
                new Product { ProductID = 1, Category = "Apples", Name = "P1" }
            });

            Cart cart = new Cart();

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

            target.AddToCart(cart, 1, null);

            Assert.AreEqual(1, cart.Lines.Count());
            Assert.AreEqual(1, cart.Lines.ElementAt(0).Product.ProductID);
        }
开发者ID:Peska,项目名称:SportsStore,代码行数:17,代码来源:CartTests.cs

示例15: CartController_AddToCart_GoesToCartScreen

        public void CartController_AddToCart_GoesToCartScreen()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1", Category = "Apples" },

            }.AsQueryable());
            Cart cart = new Cart();
            var target = new CartController(mock.Object, null);

            // Act
            var result = target.AddToCart(cart, 1, "myUrl");

            // Assert
            Assert.AreEqual<string>(result.RouteValues["action"].ToString(), "Index");
            Assert.AreEqual<string>(result.RouteValues["returnUrl"].ToString(), "myUrl");
        }
开发者ID:nitzerebbnitzerebb,项目名称:Lab2,代码行数:18,代码来源:CartControllerTests.cs


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