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