示例#1
0
        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");
        }
        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);
        }
示例#3
0
        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");
        }
示例#4
0
        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);
        }
        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");
        }
示例#6
0
        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");
        }
示例#7
0
        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);
        }
        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);
        }
示例#9
0
        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");
        }
示例#10
0
        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");
        }
        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");
        }
示例#12
0
        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);
        }
示例#13
0
        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");
        }
示例#14
0
        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);
        }
示例#15
0
        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");
        }
示例#16
0
        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");
        }
        public void Can_Paginate()
        {
            // 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"}
            });

            // create a controller and make the page size 3 items
            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");
        }
示例#18
0
        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");
        }
示例#19
0
        public void Can_Filter_Products()
        {
            //Организация - создание имитации хранилища
            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());

            //Организация - создание контроллера и установка
            //размера страницы равным трем элементам
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            //Действие
            Product[] result =
                ((ProductsListViewModel)controller.List("Cat2", 1).Model).Products.ToArray();

            //Утверждение
            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");
        }
        public void Can_Filter_Products()
        {
            controller = new ProductController(mock.Object);
            controller.pageSize = 3;

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

            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");
        }
示例#21
0
 public void Can_Filter_Products()
 {
     ProductController target = new ProductController(repository);
     target.PageSize = 1;
     ProductListViewModel result = (ProductListViewModel)((ViewResult)target.List("Soccer", null, 2)).Model;
     Product[] prodArray = result.Products.ToArray();
     Assert.AreEqual(prodArray[0].Name, "P2");
     Assert.AreEqual(result.PagingInfo.ItemsPerPage, 1);
     Assert.AreEqual(result.PagingInfo.TotalItems, 3);
     Assert.AreEqual(result.PagingInfo.TotalPages, 3);
 }
        public void TotalCountForCategories()
        {
            var controller = new ProductController(CreateRepository().Object)
            {
                PageSize = 2,
            };

            var viewModel = (ProductListViewModel)controller.List("Cat1", 2).Model;
            var pageInfo = viewModel.PagingInfo;

            Assert.AreEqual(3, pageInfo.TotalItems);
            Assert.AreEqual(2, pageInfo.TotalPages);
        }
 public void List_WhenListingTheSecondPageOfASeriesOfProducts_ShouldPaginateThemAndShowOnlyTheOnesInTheSecondPage()
 {
     // Arrange
      ProductController controller = new ProductController(repo.Object);
      controller.PageSize = 4;
      // Act
      ProductsListViewModel viewModel = (ProductsListViewModel)controller.List(page: 2).Model;
      // Assert
      List<Product> products = viewModel.Products.ToList();
      Assert.IsTrue(products.Count == 2);
      Assert.AreEqual(expected: "P5", actual: products[0].Name);
      Assert.AreEqual(expected: "P6", actual: products[1].Name);
 }
 public void List_WhenGivenACategory_ShouldLoadOnlyProductsWithThatCategory()
 {
     // Arrange
     ProductController controller = new ProductController(repo.Object);
     controller.PageSize = 4;
     // Act
     ProductsListViewModel viewModel = (ProductsListViewModel)controller.List(category: "C").Model;
     // Assert
     List<Product> products = viewModel.Products.ToList();
     Assert.IsTrue(products.Count == 2);
     Assert.AreEqual(expected: "P4", actual: products[0].Name);
     Assert.AreEqual(expected: "C", actual: products[0].Category);
     Assert.AreEqual(expected: "P5", actual: products[1].Name);
     Assert.AreEqual(expected: "C", actual: products[1].Category);
     Assert.AreEqual(expected: "C", actual: viewModel.CurrentCategory);
 }
示例#25
0
        public void Can_Filter_Products()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(GetProductArray());

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

            // 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");
        }
        public void CanSendPaginationViewModel()
        {
            var mock = CreateRepository();

            var controller = new ProductController(mock.Object)
            {
                PageSize = 2
            };

            var viewModel = (ProductListViewModel)controller.List(null, 2).Model;
            var pageInfo = viewModel.PagingInfo;

            Assert.AreEqual(6, pageInfo.TotalItems);
            Assert.AreEqual(2, pageInfo.ItemsPerPage);
            Assert.AreEqual(3, pageInfo.TotalPages);
            Assert.AreEqual(2, pageInfo.CurrentPage);
        }
示例#27
0
        public void CanPiginate()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(m => m.Products).Returns(new List<Product> {   new Product {Name = "Football", Price = 25},
                                                                      new Product {Name = "Surf Board", Price = 179},
                                                                      new Product {Name = "Running shoes", Price = 95},
                                                                      new Product {Name = "Basketball", Price = 25},
                                                                      new Product {Name = "Tennis", Price = 179}}.AsQueryable());

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

            IEnumerable<Product> result = (IEnumerable<Product>)controller.List(null, 2).Model;

            Product[]  productArray= result.ToArray();
            Assert.IsTrue(productArray.Length == 2);
        }
示例#28
0
        public void Can_Filter_Product()
        {
            // arrange
            Mock<IProductsRepository> mock = InitializeMock();

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;
            string categoryFilter = "Apples";

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

            // assert
            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "P1" && result[0].Category == categoryFilter);
            Assert.IsTrue(result[1].Name == "P2" && result[1].Category == categoryFilter);
        }
        public void Can_paginate_with_Category()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

               mock.Setup(m => m.Products).Returns(new Product[] {
               new Product{ ProductID = 1, Name = "P1", Category = "c1"},
               new Product{ ProductID = 2, Name = "P2", Category = "c1"},
               new Product{ ProductID = 3, Name = "P3", Category = "c2"},
               new Product{ ProductID = 4, Name = "P4", Category = "c3"},
               new Product{ ProductID = 5, Name = "P5"}}.AsQueryable());

               ProductController controller = new ProductController(mock.Object);

               var result = controller.List("c2").Model as ProductListViewModel;

               Product[] ProductArray = result.Products.ToArray();
               Assert.IsTrue(ProductArray.Length == 1);
               Assert.AreEqual(ProductArray[0].Name, "P3");
        }
示例#30
0
        public void Can_Paginate()
        {
            var mock = new Mock<IProductRepository>();
            mock.Setup(x => x.Products).Returns(new List<Product>
            {
                new Product {Name = "P1", ProductId = 1},
                new Product {Name = "P2", ProductId = 2},
                new Product {Name = "P3", ProductId = 3},
                new Product {Name = "P4", ProductId = 4},
                new Product {Name = "P5", ProductId = 5}
            });

            var controller = new ProductController(mock.Object) {pageSize = 3};
            var productViewModel = (ProductsListVIewModel)controller.List(null, 2).Model;
            var result = productViewModel.Products.ToArray();
            Assert.AreEqual(result.Length, 2);
            Assert.AreEqual(result[0].Name, "P4");
            Assert.AreEqual(result[1].Name, "P5");
        }