當前位置: 首頁>>代碼示例>>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方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Adding_Product_To_Cart_Goes_To_Cart_Screen

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

            //Arrage - create a Cart
            Cart cart = new Cart();

            //Arrage - 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:NJWolf,項目名稱:SportsStore,代碼行數:22,代碼來源:CartTest.cs

示例2: Can_Add_To_Cart

        public void Can_Add_To_Cart()
        {
            //Arrange - create the mosk repo
            Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID =1, Name = "P1", Category = "Apples" },
            }.AsQueryable());

            //Arrage - create a Cart
            Cart cart = new Cart();

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

            //Act - add a product to the cart
            target.AddtoCart(cart, 1, null);

            //Assert
            Assert.AreEqual(cart.Lines.Count(), 1);
            Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1);
        }
開發者ID:NJWolf,項目名稱:SportsStore,代碼行數:22,代碼來源:CartTest.cs


注:本文中的SportsStore.WebUI.Controllers.CartController.AddtoCart方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。