public void NextPageWorks()
        {
            var context = new PaginationContext(GetQuery(Constants.PageNumberQueryName, "4"), 10);
            var target = new PaginationQuery(context);

            Assert.Equal("?page[number]=5", target.NextPage);
        }
        public void NoPrevious()
        {
            var context = new PaginationContext(GetQuery(Constants.PageNumberQueryName, "0"), 10);
            var target = new PaginationQuery(context);

            Assert.Null(target.PreviousPage);
        }
        public void NextPageOnFirstPage()
        {
            var context = new PaginationContext(EmptyQuery, 10);
            var target = new PaginationQuery(context);

            Assert.Equal("?page[number]=1", target.NextPage);
        }
        public void PreviousPageWorks()
        {
            var context = new PaginationContext(GetQuery(Constants.QueryNames.PageNumber, "4"), 10);
            var target = new PaginationQuery(context);

            Assert.Equal("?page[number]=3", target.PreviousPage);
        }
        public void SupportsOtherQueryParams()
        {
            var context = new PaginationContext(GetQuery(Constants.PageNumberQueryName, "3").Concat(GetQuery("something", "hello")), 10);
            var target = new PaginationQuery(context);

            Assert.Equal("?page[number]=4&something=hello", target.NextPage);
            Assert.Equal("?page[number]=2&something=hello", target.PreviousPage);
            Assert.Equal("?page[number]=0&something=hello", target.FirstPage);
        }
        public void TakesCorrectElements()
        {
            var obj = Get.People(100);
            var context = new PaginationContext(GetQueryForPage(1), 10);
            var result = (Query.ApplyPagination(obj, context, new PersonResource())
                as IEnumerable<Person>)?.ToList();

            Assert.Equal(10, result?.Count);
            Assert.Equal("10", result?.FirstOrDefault()?.Identifier);
        }
        /// <summary>
        /// See base class documentation.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var context = new PaginationContext(
                actionContext.Request.GetQueryNameValuePairs(),
                PerPage);

            var query = GetQueryContext(actionContext);

            query.Pagination = context;
            base.OnActionExecuting(actionContext);
        }
 public ResourceSerializer(
     object value,
     ApiResource type,
     Uri baseUrl,
     IUrlPathBuilder urlBuilder,
     PaginationContext paginationContext)
 {
     _urlBuilder = urlBuilder;
     _resource = type;
     _value = value;
     _baseUrl = baseUrl;
     _paginationContext = paginationContext;
     _includedSection = new JArray();
 }
        public void FirstPageWorks()
        {
            var context = new PaginationContext(EmptyQuery, 10);
            var target = new PaginationQuery(context);

            Assert.Equal("?page[number]=0", target.FirstPage);

            context = new PaginationContext(GetQuery(Constants.PageNumberQueryName, "0"), 10);
            target = new PaginationQuery(context);

            Assert.Equal("?page[number]=0", target.FirstPage);

            context = new PaginationContext(GetQuery(Constants.PageNumberQueryName, "4"), 10);
            target = new PaginationQuery(context);

            Assert.Equal("?page[number]=0", target.FirstPage);
        }
示例#10
0
        public static object ApplyPagination(object data, PaginationContext context, ApiResource resource)
        {
            var queryable = data as IQueryable;
            if (queryable != null)
            {
                return new PaginationInterpreter(context, resource).Apply(queryable);
            }

            var enumerable = data as IEnumerable;
            if (enumerable != null)
            {
                // all queryables are enumerable, so this needs to be after
                // the queryable case
                return new PaginationInterpreter(context, resource).Apply(enumerable);
            }

            return data;
        }
示例#11
0
        public PaginationQuery(PaginationContext context)
        {
            if (context == null)
            {
                return;
            }

            if (!context.ClientFilters.ContainsKey(Constants.QueryNames.PageNumber))
            {
                context.ClientFilters.Add(Constants.QueryNames.PageNumber, null);
            }

            int page;
            var isNumber = int.TryParse(context.ClientFilters[Constants.QueryNames.PageNumber] ?? string.Empty, out page);

            FirstPage = CreateQueryString(context.ClientFilters, 0);
            NextPage = CreateQueryString(context.ClientFilters, isNumber ? page + 1 : 1);
            PreviousPage = isNumber && page > 0
                ? CreateQueryString(context.ClientFilters, page - 1)
                : null;
        }
示例#12
0
        public PaginationQuery(PaginationContext context)
        {
            if (context == null)
            {
                return;
            }

            if (!context.ClientFilters.ContainsKey(Constants.QueryNames.PageNumber))
            {
                context.ClientFilters.Add(Constants.QueryNames.PageNumber, null);
            }

            int page;
            var isNumber = int.TryParse(context.ClientFilters[Constants.QueryNames.PageNumber] ?? string.Empty, out page);

            FirstPage    = CreateQueryString(context.ClientFilters, 0);
            NextPage     = CreateQueryString(context.ClientFilters, isNumber ? page + 1 : 1);
            PreviousPage = isNumber && page > 0
                ? CreateQueryString(context.ClientFilters, page - 1)
                : null;
        }
 public PaginationInterpreter(PaginationContext context, ApiResource resource)
 {
     _context = context;
     _resource = resource;
 }
 public PaginationInterpreter(PaginationContext context, ApiResource resource)
 {
     _context  = context;
     _resource = resource;
 }
示例#15
0
 public PaginationQuery(PaginationContext context)
     : this(context, null)
 {
 }
示例#16
0
 public PagedResultQuery(PaginationContext context)
 {
     _context = context;
 }