public void Can_Filter_Products() { // arrange var controller = new ProductController(mock.Object); controller.PageSize = 3; // Act var 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[0].Category == "Cat2"); }
public void Can_Pignate() { Mock<IProductRepository> repository = new Mock<IProductRepository>(); repository.Setup(m => m.Products).Returns(new Product[]{ new Product{ProductId=1,Name="1",Description="1"}, new Product{ProductId=2,Name="2",Description="2"} , new Product{ProductId=3,Name="3",Description="3"}, new Product{ProductId=4,Name="4",Description="4"}, new Product{ProductId=5,Name="5",Description="5"} }.AsQueryable()); ProductController controller = new ProductController(repository.Object); controller.PageSize = 4; IEnumerable<Product> result = (IEnumerable<Product>)controller.List(2).Model; Assert.IsTrue(result.Count() == 1); Product[]prod= result.ToArray(); Assert.AreEqual(prod[0].Name, "5"); }
public void Can_Paginate() { // arrange var controller = new ProductController(mock.Object); controller.PageSize = 3; // Act var 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"); }
public void Generate_Category_Specific_Product_Count() { // arrange var controller = new ProductController(mock.Object); controller.PageSize = 3; // Act var cat1 = (ProductsListViewModel)controller.List("Cat1").Model; var cat2 = (ProductsListViewModel)controller.List("Cat2").Model; var cat3 = (ProductsListViewModel)controller.List("Cat3").Model; var all = (ProductsListViewModel)controller.List(null).Model; // Assert Assert.AreEqual(cat1.PagingInfo.TotalItems, 2); Assert.AreEqual(cat2.PagingInfo.TotalItems, 2); Assert.AreEqual(cat3.PagingInfo.TotalItems, 1); Assert.AreEqual(all.PagingInfo.TotalItems, 5); }
public void Can_Send_Pagination_View_Model() { // arrange var controller = new ProductController(mock.Object); controller.PageSize = 3; // Act var result = (ProductsListViewModel)controller.List(null, 2).Model; // Assert var pagingInfo = result.PagingInfo; Assert.AreEqual(pagingInfo.CurrentPage, 2); Assert.AreEqual(pagingInfo.ItemsPerPage, 3); Assert.AreEqual(pagingInfo.TotalItems, 5); Assert.AreEqual(pagingInfo.TotalPages, 2); }