Ejemplo n.º 1
0
        public void CanViewProductsFromASingleCategory()
        {
            // 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);

            var result = controller.List("Roman", 1);

            var viewModel = (ProductsListViewModel)result.ViewData.Model;
            viewModel.Products.Count.ShouldEqual(1);
            viewModel.Products[0].Name.ShouldEqual("Neptune");
            viewModel.CurrentCategory.ShouldEqual("Roman");
        }
Ejemplo n.º 2
0
        public void CanViewProductsFromAllCategories()
        {
            // 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 we ask for the all products category
            var result = controller.List(null, 1);

            // assert: we get both products
            var viewModel = (ProductsListViewModel)result.ViewData.Model;
            viewModel.Products.Count.ShouldEqual(2);
            viewModel.Products[0].Name.ShouldEqual("Artemis");
            viewModel.Products[1].Name.ShouldEqual("Neptune");
        }
Ejemplo n.º 3
0
        public void ProductListsIncludeCorrectPageNumbers()
        {
            // 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);
        }
Ejemplo n.º 4
0
        public void CanViewASinglePageOfProducts()
        {
            // 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 will 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");
        }