public void PageCount(int pageSize, int totalEntries, int expectedPages) { var range = Enumerable.Range(1, totalEntries).AsQueryable(); var result = PaginationService.Paginate(range, 1, pageSize); Assert.Equal(expectedPages, result.PageCount); }
public void PaginationWorks() { List <Article> data = new List <Article> { new Article { Id = 0, Title = "T0" }, new Article { Id = 1, Title = "T1" }, new Article { Id = 2, Title = "T2" }, new Article { Id = 3, Title = "T3" }, new Article { Id = 4, Title = "T4" }, }; int pageSize = 2; var res0 = PaginationService.Paginate(data, 2, pageSize).ToList(); var res1 = PaginationService.Paginate(data, 3, pageSize).ToList(); var res2 = PaginationService.Paginate(data, 4, pageSize).ToList(); Assert.IsTrue(res0.Count() == 2); Assert.IsTrue(res1.Count() == 1); Assert.IsTrue(res2.Count() == 0); Assert.IsTrue(res0[0].Title == "T2"); Assert.IsTrue(res1[0].Title == "T4"); }
public void CustomCountPageCount(int pageSize, int expectedPages) { var range = Enumerable.Range(1, 10).AsQueryable(); var result = PaginationService.Paginate(range, 1, pageSize, (x) => 400); Assert.Equal(expectedPages, result.PageCount); }
public void BasicPagination(int page, int pageSize, int start, int end) { var expected = Enumerable.Range(start, end - start + 1); var result = PaginationService.Paginate(Data, page, pageSize); Assert.Equal(page, result.Page); Assert.Equal(pageSize, result.PageSize); Assert.Equal(expected, result.Entries.AsEnumerable()); }
public ViewResult All(int page = 1, String category = null, String searchText = null) { ArticlesSummariesViewModel model = new ArticlesSummariesViewModel(category, searchText); List <Article> articles = articleRepository.GetAllArticles(category: category, searchText: searchText); model.PaginationModel = PaginationService.GetDefaultPaginationModel(articles, page); articles = PaginationService.Paginate(articles, page).ToList(); model.Articles = articles; return(View(model)); }