當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。