當前位置: 首頁>>代碼示例>>C#>>正文


C# ProductController.ProductList方法代碼示例

本文整理匯總了C#中SportsStore.WebUI.Controllers.ProductController.ProductList方法的典型用法代碼示例。如果您正苦於以下問題:C# ProductController.ProductList方法的具體用法?C# ProductController.ProductList怎麽用?C# ProductController.ProductList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SportsStore.WebUI.Controllers.ProductController的用法示例。


在下文中一共展示了ProductController.ProductList方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Can_Paginate

        public void Can_Paginate()
        {
            // 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"},
            new Product {ProductID = 2, Name = "P2"},
            new Product {ProductID = 3, Name = "P3"},
            new Product {ProductID = 4, Name = "P4"},
            new Product {ProductID = 5, Name = "P5"}
            }.AsQueryable());

            // create a controller and make the page size 3 items
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Action
            ProductsListViewModel result = (ProductsListViewModel)controller.ProductList(null, 2).Model;

            // Assert
            Product[] prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");
        }
開發者ID:gustavarrhenius,項目名稱:Lab3,代碼行數:26,代碼來源:PaginationTest.cs

示例2: Generate_Category_Specific_Product_Count

        public void Generate_Category_Specific_Product_Count()
        {
            // 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 = Cat1},
                   new Product {ProductID = 2, Name = "P2", Category = Cat2},
                   new Product {ProductID = 3, Name = "P3", Category = Cat1},
                   new Product {ProductID = 4, Name = "P4", Category = Cat2},
                   new Product {ProductID = 5, Name = "P5", Category = Cat3}
               }.AsQueryable());

                // Arrange - create a controller and make the page size 3 items
                ProductController target = new ProductController(mock.Object);
                target.PageSize = 3;
                // Action - test the product counts for different categories
                int res1 = ((ProductsListViewModel)target.ProductList("Cat1").Model).PagingInfo.TotalItems;
                int res2 = ((ProductsListViewModel)target.ProductList("Cat2").Model).PagingInfo.TotalItems;
                int res3 = ((ProductsListViewModel)target.ProductList("Cat3").Model).PagingInfo.TotalItems;
                int resAll = ((ProductsListViewModel)target.ProductList(null).Model).PagingInfo.TotalItems;
                // Assert
                Assert.AreEqual(res1, 2);
                Assert.AreEqual(res2, 2);
                Assert.AreEqual(res3, 1);
                Assert.AreEqual(resAll, 5);
        }
開發者ID:gustavarrhenius,項目名稱:Lab3,代碼行數:27,代碼來源:ProductTest.cs


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