Example #1
0
        public void Can_View_A_Single_Page_Of_Products()
        {
            var products = new Product[] {
                new Product {
                    Name = "P1"
                },
                new Product {
                    Name = "P2"
                },
                new Product {
                    Name = "P3"
                },
                new Product {
                    Name = "P4"
                },
                new Product {
                    Name = "P5"
                },
                new Product {
                    Name = "P6"
                },
            };

            var secondPage = new Product[3];

            Array.Copy(products, 3, secondPage, 0, 3);

            var repo = new Mock <IEntityRepository <Product> >();

            repo.SetupGet(r => r.Query).Returns(products.AsQueryable());

            var controller = new ProductsController(repo.Object);

            controller.PageSize = 3;

            var result = controller.List(2);

            EnumerableAssert.AreEqual(secondPage, ((ProductListViewModel)result.ViewData.Model).Products);
        }
Example #2
0
        public void Default_list_products_from_all_Categories()
        {
            var products = new Product[] {
                new Product {
                    Name = "P1", Category = "C1"
                },
                new Product {
                    Name = "P2", Category = "C2"
                },
            };

            var repo = new Mock <IEntityRepository <Product> >();

            repo.SetupGet(r => r.Query).Returns(products.AsQueryable());

            var controller = new ProductsController(repo.Object);

            controller.PageSize = 2;

            var result = controller.List(1);

            EnumerableAssert.AreEqual(products, ((ProductListViewModel)result.ViewData.Model).Products);
        }
Example #3
0
        public void Can_filter_products_by_category()
        {
            var products = new Product[] {
                new Product {
                    Name = "P1", Category = "C1"
                },
                new Product {
                    Name = "P2", Category = "C2"
                },
            };

            var repo = new Mock <IEntityRepository <Product> >();

            repo.SetupGet(r => r.Query).Returns(products.AsQueryable());

            var controller = new ProductsController(repo.Object);

            controller.PageSize = 2;

            var result    = controller.List(1, "C1");
            var viewModel = result.ViewData.Model as ProductListViewModel;

            EnumerableAssert.AreEqual(products.Where(p => p.Category == "C1"), viewModel.Products);
        }