public PagedQueryable <T> Paginate <T>(SortedQueryable <T> source) { var limit = source.Items.Count(); var paginationInfo = new PaginationInfo(0, limit, limit, 1); return(new PagedQueryable <T>(source.Items, paginationInfo, source.Sorting)); }
public PagedQueryable <T> Paginate <T>(SortedQueryable <T> source) { var items = source.Items; var limit = items.LongCount(); var paginationInfo = new PaginationInfo(0, (int)limit, false); return(new PagedQueryable <T>(source.Items, paginationInfo, source.Sorting)); }
public When_creating_a_no_pagination_request() { var fixture = new Fixture(); Sut = new NoPaginationRequest(); var items = fixture .CreateMany <Guid>(Math.Abs(fixture.Create <int>()) + 1) .Select((guid, i) => new KeyValuePair <int, Guid>(i, guid)); _queryableItems = new SortedQueryable <KeyValuePair <int, Guid> >( items.AsQueryable(), new SortingHeader("Key", SortOrder.Ascending)); }
protected PaginationTestContext() { Fixture = new Fixture(); // ReSharper disable once VirtualMemberCallInConstructor Sut = SetUp(); var listSize = Sut.Offset + Sut.Limit + CreatePositive(); var items = Fixture .CreateMany <Guid>(listSize) .Select((guid, i) => new KeyValuePair <int, Guid>(i, guid)); QueryableItems = new SortedQueryable <KeyValuePair <int, Guid> >( items.AsQueryable(), new SortingHeader("Key", SortOrder.Ascending)); }
protected override PaginationRequest SetUp() { _limit = CreatePositive(); _offset = CreatePositive(); var listSize = _offset + _limit - 1; var items = Fixture .CreateMany <Guid>(listSize) .Select((guid, i) => new KeyValuePair <int, Guid>(i, guid)); _queryableItems = new SortedQueryable <KeyValuePair <int, Guid> >( items.AsQueryable(), new SortingHeader("Key", SortOrder.Ascending)); return(new PaginationRequest(_offset, _limit)); }
public PagedQueryable <T> Paginate <T>(SortedQueryable <T> source) { var items = source.Items; var itemsInRequestedPage = new List <T>().AsQueryable(); if (Limit > 0) { itemsInRequestedPage = items .Skip(Offset) .Take(Limit); } var totalItemSize = items.Count(); var totalPages = (int)Math.Ceiling((double)totalItemSize / Limit); var paginationInfo = new PaginationInfo(Offset, Limit, totalItemSize, totalPages); return(new PagedQueryable <T>(itemsInRequestedPage, paginationInfo, source.Sorting)); }
public PagedQueryable <T> Paginate <T>(SortedQueryable <T> source) { var items = source.Items; if (Limit == 0) { return(new PagedQueryable <T>( new List <T>().AsQueryable(), new PaginationInfo(Offset, Limit, false), source.Sorting)); } var itemsInRequestedPage = items .Skip(Offset) .Take(Limit + 1); return(new PagedQueryable <T>( itemsInRequestedPage.Take(Limit), new PaginationInfo(Offset, Limit, itemsInRequestedPage.Count() > Limit), source.Sorting)); }
public static PagedQueryable <T> WithPagination <T>(this SortedQueryable <T> source, IPaginationRequest paginationRequest) => paginationRequest.Paginate(source);