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


C# ProductController.List方法代码示例

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


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

示例1: Can_paginate

        public void Can_paginate()
        {
            ProductController target = new ProductController(repository);
            target.PageSize = 3;

            ProductListViewModel result = (ProductListViewModel)((ViewResult)target.List(null,null,2)).Model;
            Product[] prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");

            result = (ProductListViewModel)((ViewResult)target.List(null, null)).Model;
            prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 3);
            Assert.AreEqual(prodArray[0].Name, "P1");
            Assert.AreEqual(prodArray[1].Name, "P2");
            Assert.AreEqual(prodArray[2].Name, "P3");

            result = (ProductListViewModel)((ViewResult)target.List(null, null, -1)).Model;
            prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 3);
            Assert.AreEqual(prodArray[0].Name, "P1");
            Assert.AreEqual(prodArray[1].Name, "P2");
            Assert.AreEqual(prodArray[2].Name, "P3");
        }
开发者ID:Shiloff,项目名称:SportsStore,代码行数:25,代码来源:UnitTest1.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.List("Cat1").Model).PagingInfo.TotalItems;
            int res2 = ((ProductsListViewModel)target.List("Cat2").Model).PagingInfo.TotalItems;
            int res3 = ((ProductsListViewModel)target.List("Cat3").Model).PagingInfo.TotalItems;
            int resAll = ((ProductsListViewModel)target.List(null).Model).PagingInfo.TotalItems;

            // Assert
            Assert.AreEqual(res1, 2);
            Assert.AreEqual(res2, 2);
            Assert.AreEqual(res3, 1);
            Assert.AreEqual(resAll, 5);
        }
开发者ID:evkap,项目名称:AspNetMvcTestApp,代码行数:28,代码来源:ProductControllerTest.cs

示例3: Can_Paginate

        public void Can_Paginate()
        {
            //Arrange
            // - create the mock repository
            var 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
            var controller = new ProductController(mock.Object) { PageSize = 3 };

            // Action
            var result = (ProductsListViewModel)controller.List(2).Model;

            // Assert
            var prodArray = result.Products.ToArray();
            Assert.AreEqual(2, prodArray.Length);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");
        }
开发者ID:sunston,项目名称:SportStore,代码行数:26,代码来源:UnitTestPagination.cs

示例4: CanGeneratePageLinks

        public void CanGeneratePageLinks()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(m => m.Products).Returns(new List<Product> {   new Product {Category = "Football", Description = "Ball", Price = 49, Name = "Adidas Euro 2012 Match Football - Tango 12"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 38, Name = "Mitre Tensile Football"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 25, Name = "Adidas Tango Football : Pasadena"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 25, Name = "Adidas Uefa Europa League Match Ball : 2011/12"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 25, Name = "Mitre Ciero Match Football"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 14.95M, Name = "Mitre Football Ball : Astro Division"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 12.95M, Name = "Mitre Match Football : Campeon"},

                                                                      new Product {Category = "Football", Name = "Nike T90 Laser IV", Price = 49, Description = "Lighter, deadlier, more powerful. The T90 Laser IV really is the Perfect Strike"},
                                                                      new Product {Category = "Football", Name = "Nike Mercurial Vapor III", Price = 38, Description = "A Blast from the past - one of our most popular ever articles is all about the classic MVIII!"},

                                                                      new Product {Category = "Tennis", Name = "Wilson BLX Six.One 95 18x20", Price = 86, Description = "New A tighter, more control oriented stringbed plus improved feel separates this one from the pack. A confidence inspiring racquet for advanced players. 18/20 string pattern, standard length, 95 sq. inch headsize, traditional head light balance."},
                                                                      new Product {Category = "Tennis", Name = "Wilson BLX Six.One Team", Price = 155, Description = "New This update features a more open 16x18 string pattern than its predecessor for added pop and topspin. Great feel and a clean response will impress intermediate to advanced level players. Headsize: 95 sq. in. Length: 27. Strung weight: 10.7 oz."},
                                                                      new Product {Category = "Tennis", Name = "Wilson BLX Six.One 95 16x18", Price = 79, Description = "New An updated look with excellent maneuverability and access to spin, this easy to swing racket is great for 4.0+ level players. Strung weight: 10.4 ounces. Swingweight: 313. Headsize: 100 square inches."},
                                                                      new Product {Category = "Tennis", Name = "Boris Becker Delta Core London", Price = 79, Description = "Feel, comfort, control, maneuverability, power and stability, this one has it all. A truly impressive option for the 4.0+ level player this one comes with a standard length, 98sq.in headsize and 16x19 string pattern."},
                                                                    }.AsQueryable());

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;
            controller.List("Football", 1);

            int actual = controller.pagingInfo.TotalPages;
            int expected = 3;
            Assert.AreEqual(expected, actual);
        }
开发者ID:duda92,项目名称:SportsStore,代码行数:29,代码来源:MyTests.cs

示例5: Can_List_Paginate

        public void Can_List_Paginate()
        {
            // arrange
            // create mock repository
            var productRepository = new Mock<IProductRepository>();
            productRepository.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());

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

            // act
            var actionResult = controller.List(null, 2);

            // assert
            var productsListViewModel = actionResult.Model as ProductsListViewModel;

            Assert.IsNotNull(productsListViewModel);
            Assert.IsTrue(productsListViewModel.Products.Count() == 2);
            Assert.AreEqual(productsListViewModel.Products.ToArray()[0].Name, "P4");
            Assert.AreEqual(productsListViewModel.Products.ToArray()[1].Name, "P5");
        }
开发者ID:moacap,项目名称:SportsStoreMVC3,代码行数:29,代码来源:ProductControllerTests.cs

示例6: CanPaginate

        public void CanPaginate()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new List<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"},
                new Product {ProductId = 6, Name = "P6"},
                });

            ProductController prod = new ProductController(mock.Object);
            prod.PageSize = 3;

            //act
            ProductsListViewModel result = (ProductsListViewModel)prod.List(null, 2).Model;
            //IEnumerable<Product> result = prod.List(2).Model as IEnumerable<Product>;

            //assert
            Product[] prodArr = result.Products.ToArray();
            Assert.IsTrue(prodArr.Length == 3);
            Assert.AreEqual(prodArr[0].Name, "P4");
        }
开发者ID:denozavr,项目名称:SportStore,代码行数:25,代码来源:UnitTest1.cs

示例7: Can_Send_Pagination_View_Model

        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
            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()
                );
            var controller = new ProductController(mock.Object) { PageSize = 3 };
            var result = (ProductsListViewModel)controller.List(2).Model;

            //Assert
            Assert.AreEqual(2, result.PagingInfo.CurrentPage);
            Assert.AreEqual(3, result.PagingInfo.ItemsPerPage);
            Assert.AreEqual(5, result.PagingInfo.TotalItems);
            Assert.AreEqual(2, result.PagingInfo.TotalPages);
        }
开发者ID:sunston,项目名称:SportStore,代码行数:27,代码来源:UnitTestPagination.cs

示例8: Can_Send_Pagination_View_Model

        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
            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"}
            });

            // Arrange
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;
            
            // Act
            ProductsListViewModel result = (ProductsListViewModel)controller.List(null, 2).Model;
            
            // Assert
            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
开发者ID:agnium-academy,项目名称:abyor-rpg-trioandianto,代码行数:27,代码来源:UnitTest1.cs

示例9: CanPaginate

        public void CanPaginate()
        {
            // Arrange
            Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
            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());

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Act
            ProductsListViewModel result = (ProductsListViewModel) controller.List(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:joshhoffman,项目名称:SportsStore,代码行数:25,代码来源:UnitTest1.cs

示例10: CanPaginate

        public void CanPaginate()
        {
            //arrange
            var target = new Mock<IProductRepository>();

            target.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());

            //arrange
            var productController = new ProductController(target.Object);
            productController.PageSize = 3;

            //act
            var result = (ProductsListViewModel)productController.List(null, 2).Model;

            //assert
            var prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "p4");
            Assert.AreEqual(prodArray[1].Name, "p5");
        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:27,代码来源:Products.cs

示例11: Can_Filter_Products

        public void Can_Filter_Products()
        {
            // arrange - mock repo
            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"},
            });

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

            // action (act)
            Product[] result = ((ProductsListViewModel)controller.List("Cat2", 1).Model).Products.ToArray();

            // Assert
            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "P2" && result[0].Category == "Cat2");
            Assert.IsTrue(result[1].Name == "P4" && result[1].Category == "Cat2");
        }
开发者ID:pixelsyndicate,项目名称:Pro_AspNet_MVC_5_book,代码行数:25,代码来源:PagingUnitTests.cs

示例12: CanSendPaginationViewModel

        public void CanSendPaginationViewModel()
        {
            //arrange
            var target = new Mock<IProductRepository>();

            target.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());

            //arrange
            var productController = new ProductController(target.Object);
            productController.PageSize = 3;

            //act
            var result = (ProductsListViewModel) productController.List(null, 2).Model;

            //assert
            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:27,代码来源:Products.cs

示例13: Can_Filter_Products

        public void Can_Filter_Products()
        {
            //arrange
            var mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new[]
                {
                    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
            var controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            //action
            //controller.List() have default second parameter = 1
            Product[] result = ((ProductsListViewModel) controller.List("Cat2").Model).Products.ToArray();

            //assert
            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "P2" && result[0].Category == "Cat2");
            Assert.IsTrue(result[1].Name == "P4" && result[0].Category == "Cat2");
        }
开发者ID:roszman,项目名称:SportsStore,代码行数:25,代码来源:UnitTest1.cs

示例14: Can_Send_Pagination_View_Model

        public void Can_Send_Pagination_View_Model()
        {
            // 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());

            // Arrange - create a controller and make the page size 3 items

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Action

            ProductsListViewModel result = (ProductsListViewModel)controller.List("Soccer", 2).Model;

            // Assert

            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
开发者ID:gustavarrhenius,项目名称:Lab3,代码行数:30,代码来源:ViewModelTest.cs

示例15: Can_Paginate

        public void Can_Paginate()
        {
            // Arrange
            Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
            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"}
            });

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Act
            IEnumerable<Product> result = (IEnumerable<Product>) controller.List(2).Model;

            // Assert
            Product[] prodArray = result.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");
        }
开发者ID:ttchongtc,项目名称:netmvctutorial,代码行数:25,代码来源:UnitTest1.cs


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