public void Product_Lists_Include_Correct_Page_Numbers() { // Arrange: If there are five products in the repository var mockRepository = UnitTestHelpers.MockProductsRepository ( new Product { Name = "p1" }, new Product { Name = "p2" }, new Product { Name = "p3" }, new Product { Name = "p4" }, new Product { Name = "p5" } ); // Arrange: Create a new ProductsController with the mock repository // and a page size of 3 var controller = new ProductsController(mockRepository) { PageSize = 3 }; // Act: Grab the view data model for page 2 var result = controller.List(2); // Assert: Check all the data in the model var viewModel = (ProductListViewModel) result.ViewData.Model ; PagingInfo pagingInfo = viewModel.PagingInfo ; pagingInfo.CurrentPage.ShouldEqual(2); pagingInfo.TotalPages.ShouldEqual(2); pagingInfo.ItemsPerPage.ShouldEqual(3); pagingInfo.TotalItems.ShouldEqual(5); }
public void Can_View_A_Single_Page_Of_Products() { // Arrange: Put 5 products in a mock repository IProductsRepository repository = UnitTestHelpers.MockProductsRepository ( new Product { Name = "p1" }, new Product { Name = "p2" }, new Product { Name = "p3" }, new Product { Name = "p4" }, new Product { Name = "p5" } ); // Create a products controller // Again, we're using an implicitly typed variable here var controller = new ProductsController(repository); // Set the controller's page size to 3 // We haven't implemented the PageSize property yet // so the test will fail controller.PageSize = 3; // Act: Ask the controller for page 2 var result = controller.List(2); // Assert: ... they'll see the last two products? var displayedProducts = (ProductListViewModel)result.ViewData.Model; displayedProducts.Products.Count.ShouldEqual(2); displayedProducts.Products[0].Name.ShouldEqual("p4"); displayedProducts.Products[1].Name.ShouldEqual("p5"); }
public void Can_View_Products_From_A_Single_Category() { // Arrange: If two products are in two different categories... IProductsRepository repository = UnitTestHelpers.MockProductsRepository( new Product { Name = "Artemis", Category = "Greek" }, new Product { Name = "Neptune", Category = "Roman" } ); var controller = new ProductsController(repository); // Act: ... then when we ask for the "All Products" category var result = controller.List("Roman", 1); // Arrange: ... we get only the product from that category var viewModel = (ProductsListViewModel)result.ViewData.Model; var displayedProducts = viewModel.Products; displayedProducts.Count.ShouldEqual(1); displayedProducts[0].Name.ShouldEqual("Neptune"); viewModel.CurrentCategory.ShouldEqual("Roman"); }
public void Can_View_A_Single_Page_Of_Products() { // Arrange: If there are 5 products in the repository... IProductsRepository repository = UnitTestHelpers.MockProductsRepository( new Product { Name = "P1" }, new Product { Name = "P2" }, new Product { Name = "P3" }, new Product { Name = "P4" }, new Product { Name = "P5" } ); var controller = new ProductsController(repository); controller.PageSize = 3; // Act: ... then when the user asks for the second page (PageSize=3)... var result = controller.List(null, 2); // Assert: ... they'll just see the last two products. var viewModel = (ProductsListViewModel)result.ViewData.Model; var displayedProducts = viewModel.Products; displayedProducts.Count.ShouldEqual(2); displayedProducts[0].Name.ShouldEqual("P4"); displayedProducts[1].Name.ShouldEqual("P5"); }
public void Product_Lists_Include_Correct_Page_Numbers() { // Arrange: If there are five products in the repository... var mockRepository = UnitTestHelpers.MockProductsRepository( new Product { Name = "P1" }, new Product { Name = "P2" }, new Product { Name = "P3" }, new Product { Name = "P4" }, new Product { Name = "P5" } ); var controller = new ProductsController(mockRepository) { PageSize = 3 }; // Act: ... then when the user asks for the second page (PageSize=3)... var result = controller.List(null, 2); // Assert: ... they'll see page links matching the following var viewModel = (ProductsListViewModel)result.ViewData.Model; PagingInfo pagingInfo = viewModel.PagingInfo; pagingInfo.CurrentPage.ShouldEqual(2); pagingInfo.ItemsPerPage.ShouldEqual(3); pagingInfo.TotalItems.ShouldEqual(5); pagingInfo.TotalPages.ShouldEqual(2); }
public void Product_Lists_Include_Correct_Page_Numbers() { var mockRepository = UnitTestHelpers.MockProductsRepository( new Product { Name = "P1" } , new Product { Name = "P2" } , new Product { Name = "P3" } , new Product { Name = "P4" } , new Product { Name = "P5" } ); var controller = new ProductsController(mockRepository){PageSize = 3}; var result = controller.List(null, 2); var viewModel = (ProductsListViewModel) result.ViewData.Model; PagingInfo pagingInfo = viewModel.PagingInfo; pagingInfo.CurrentPage.ShouldEqual(2); pagingInfo.ItemsPerPage.ShouldEqual(3); pagingInfo.TotalItems.ShouldEqual(5); pagingInfo.TotalPages.ShouldEqual(2); }