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


C# Controllers.ProductController类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: Can_paginate

        public void Can_paginate()
        {
            // Arrange
            // - Mock 리파지터리를 생성한다.
            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());

            // 컨트롤러를 생성하고 페이지 크기를 3개로 지정한다.
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Action
            ProductsListViewModel result = (ProductsListViewModel)controller.List(null, 2).ViewData.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:yeobi,项目名称:SportsStore,代码行数:27,代码来源:ProductControllerTest.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: Cannot_Retrieve_Image_Data_For_Invalid_Id

        public void Cannot_Retrieve_Image_Data_For_Invalid_Id()
        {
            // Arrange
            Product prod = new Product
            {
                ProductId = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            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" }
            }.AsQueryable());

            ProductController target = new ProductController(mock.Object);

            // Act
            ActionResult result = target.GetImage(100);

            // Assert
            Assert.IsNull(result);
        }
开发者ID:nhebb,项目名称:ProMVC5,代码行数:25,代码来源:ImageTests.cs

示例9: 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

示例10: Cant_Retrieve_NonExistint_Image_Data

        public void Cant_Retrieve_NonExistint_Image_Data()
        {
            // Arrange - create a Product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            // 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"},
                prod,
                new Product {ProductID = 3, Name = "P3"}
            }.AsQueryable());

            // Arrange - create the controller
            ProductController target = new ProductController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(3);

            // Assert
            Assert.IsNull(result);
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:28,代码来源:ProductControllerTest.cs

示例11: 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

示例12: 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

示例13: Can_Retrieve_Image_Data

        public void Can_Retrieve_Image_Data()
        {
            Product product = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] {},
                ImageMimeType = "image/png"
            };

            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID = 1, Name = "P1"},
                product,
                new Product {ProductID = 1, Name = "P3"}
            }.AsQueryable());

            ProductController target = new ProductController(mock.Object);

            ActionResult result = target.GetImage(2);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(product.ImageMimeType,((FileResult)result).ContentType);
        }
开发者ID:SHassona,项目名称:Personal-Repository,代码行数:26,代码来源:ImageTests.cs

示例14: Can_Retreive_Image_Data

        public void Can_Retreive_Image_Data()
        {
            //Arrange - create a product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "test",
                ImageData = new Byte[] { },
                ImageMimeType = "image/png"

            };

            //Arrange -create a mock repository

            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(p => p.Products).Returns(new Product[] { 
                new Product{ProductID=1,Name="P1"},
                prod,
                new Product{ProductID=3,Name="P3"}           
            
            }.AsQueryable());

            ProductController controller = new ProductController(mock.Object);

            ActionResult result = controller.GetImage(2);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType);

        }
开发者ID:KannugoPrithvi,项目名称:SportStore,代码行数:32,代码来源:ImageTests.cs

示例15: Can_Filter_Products

        public void Can_Filter_Products()
        {
            //Arrange
            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
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            //Act
            Product[] res = ((ProductListViewModel)controller.List("Cat2",1).Model).Products.ToArray();

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


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