Esempio n. 1
0
        public void Can_Paginate()
        {
            // Arrange
            var repositoryStub = new eStore.Domain.Abstract.Fakes.StubIProductRepository();
            repositoryStub.ProductsGet = () =>
            {
                return new List<Product> { 
                    new Product {ProductID = 1, Name="1"},
                    new Product {ProductID = 2, Name="2"},
                    new Product {ProductID = 3, Name="3"},
                    new Product {ProductID = 4, Name="4"},
                    new Product {ProductID = 5, Name="5"},
                };
            };

            var productController = new ProductController(repositoryStub);
            productController.PageSize = 3;

            // Act
            var result = ((ProductsListViewModel)productController.List(null, 2).Model).Products.ToList();

            // Assert
            Assert.IsTrue(result.Count == 2);
            Assert.AreEqual(result[0].Name, "4");
            Assert.AreEqual(result[1].Name, "5");
        }
Esempio n. 2
0
        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
            var repositoryStub = new eStore.Domain.Abstract.Fakes.StubIProductRepository();
            repositoryStub.ProductsGet = () =>
            {
                return new List<Product> { 
                    new Product {ProductID = 1, Name="1"},
                    new Product {ProductID = 2, Name="2"},
                    new Product {ProductID = 3, Name="3"},
                    new Product {ProductID = 4, Name="4"},
                    new Product {ProductID = 5, Name="5"},
                };
            };

            var productController = new ProductController(repositoryStub);
            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.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Esempio n. 3
0
        public void Generate_Category_Specific_Product_Count()
        {
            // Arrange
            var repositoryStub = new eStore.Domain.Abstract.Fakes.StubIProductRepository();
            repositoryStub.ProductsGet = () =>
            {
                return new List<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"}
                };
            };

            ProductController target = new ProductController(repositoryStub);
            target.PageSize = 3;

            // Action
            var res1 = ((ProductsListViewModel)target.List("Cat1").Model).PagingInfo.TotalItems;
            var res2 = ((ProductsListViewModel)target.List("Cat2").Model).PagingInfo.TotalItems;
            var res3 = ((ProductsListViewModel)target.List("Cat3").Model).PagingInfo.TotalItems;
            var 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);
        }