public void ParsesEmpty()
        {
            var context = new SortingContext(Enumerable.Empty<KeyValuePair<string, string>>());

            var actual = context.Properties;

            Assert.Equal(Enumerable.Empty<SortingProperty>(), actual);
        }
        /// <summary>
        /// See base class documentation.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var queryParams = actionContext.Request.GetQueryNameValuePairs().ToList();
            var sorting = new SortingContext(queryParams);
            var filtering = new FilteringContext(queryParams);

            var queryContext = GetQueryContext(actionContext);

            queryContext.Sorting = sorting;
            queryContext.Filtering = filtering;

            base.OnActionExecuting(actionContext);
        }
        internal void ParsesCorrectly(string query, string[] properties, SortingDirection[] directions)
        {
            var context = new SortingContext(GetQuery(query));
            var expected = properties.Zip(directions, (s, d) => new
            {
                Name = s,
                Direction = d
            }).ToList();
            var actual = context.Properties.Select(p => new
            {
                p.Name,
                p.Direction
            }).ToList();

            Assert.Equal(expected, actual);
        }
Exemple #4
0
        public static object ApplySorting(object data, SortingContext context, ApiResource resource)
        {
            var queryable = data as IQueryable;
            if (queryable != null)
            {
                return new SortingInterpreter(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 SortingInterpreter(context, resource).Apply(enumerable);
            }

            return data;
        }
 public SortingInterpreter(SortingContext context, ApiResource resource)
 {
     _context = context;
     _resource = resource;
 }
 public SortingInterpreter(SortingContext context, ApiResource resource)
 {
     _context  = context;
     _resource = resource;
 }