示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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));
        }
示例#7
0
        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));
        }
示例#8
0
 public static PagedQueryable <T> WithPagination <T>(this SortedQueryable <T> source, IPaginationRequest paginationRequest)
 => paginationRequest.Paginate(source);