diff --git a/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs b/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs index 6b79dda..649280a 100644 --- a/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs +++ b/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs @@ -4,11 +4,11 @@ namespace PoweredSoft.DynamicQuery.Core { public interface INoSortInterceptor : IQueryInterceptor { - IQueryable InterceptNoSort(IQueryable queryable); + IQueryable InterceptNoSort(IQueryCriteria criteria, IQueryable queryable); } public interface INoSortInterceptor : IQueryInterceptor { - IQueryable InterceptNoSort(IQueryable queryable); + IQueryable InterceptNoSort(IQueryCriteria criteria, IQueryable queryable); } } diff --git a/PoweredSoft.DynamicQuery.Test/NoSortTests.cs b/PoweredSoft.DynamicQuery.Test/NoSortTests.cs new file mode 100644 index 0000000..e064917 --- /dev/null +++ b/PoweredSoft.DynamicQuery.Test/NoSortTests.cs @@ -0,0 +1,89 @@ +using Microsoft.EntityFrameworkCore; +using PoweredSoft.DynamicQuery.Core; +using PoweredSoft.DynamicQuery.Test.Mock; +using PoweredSoft.DynamicLinq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace PoweredSoft.DynamicQuery.Test +{ + public class NoSortTests + { + private class MockNoSortInterceptor : INoSortInterceptor + { + public IQueryable InterceptNoSort(IQueryCriteria criteria, IQueryable queryable) + { + return queryable.OrderBy("Customer.LastName"); + } + } + + private class MockNoSortGenericInterceptor : + INoSortInterceptor, + INoSortInterceptor + { + public IQueryable InterceptNoSort(IQueryCriteria criteria, IQueryable queryable) + { + return queryable.OrderBy(t => t.Customer.LastName); + } + + public IQueryable InterceptNoSort(IQueryCriteria criteria, IQueryable queryable) + { + // should not go in here. + throw new NotImplementedException(); + } + } + + [Fact] + public void NonGeneric() + { + MockContextFactory.SeedAndTestContextFor("NoSortTests_NonGeneric", TestSeeders.SimpleSeedScenario, ctx => + { + var criteria = new QueryCriteria(); + var interceptor = new MockNoSortInterceptor(); + + // queryable of orders. + var queryable = ctx.Orders.AsQueryable(); + + // pass into the interceptor. + queryable = (IQueryable)interceptor.InterceptNoSort(criteria, queryable); + + // query handler should pass by the same interceptor. + var queryHandler = new QueryHandler(); + queryHandler.AddInterceptor(interceptor); + var result = queryHandler.Execute(ctx.Orders, criteria); + + // compare results. + var expected = queryable.ToList(); + Assert.Equal(expected, result.Data); + }); + } + + [Fact] + public void Generic() + { + MockContextFactory.SeedAndTestContextFor("NoSortTests_Generic", TestSeeders.SimpleSeedScenario, ctx => + { + var criteria = new QueryCriteria(); + var interceptor = new MockNoSortGenericInterceptor(); + + // queryable of orders. + var queryable = ctx.Orders.AsQueryable(); + + // pass into the interceptor. + queryable = interceptor.InterceptNoSort(criteria, queryable); + + // query handler should pass by the same interceptor. + var queryHandler = new QueryHandler(); + queryHandler.AddInterceptor(interceptor); + var result = queryHandler.Execute(ctx.Orders, criteria); + + // compare results. + var expected = queryable.ToList(); + Assert.Equal(expected, result.Data); + }); + } + } +} diff --git a/PoweredSoft.DynamicQuery/QueryHandlerBase.cs b/PoweredSoft.DynamicQuery/QueryHandlerBase.cs index 4109b88..c1568f8 100644 --- a/PoweredSoft.DynamicQuery/QueryHandlerBase.cs +++ b/PoweredSoft.DynamicQuery/QueryHandlerBase.cs @@ -153,11 +153,11 @@ namespace PoweredSoft.DynamicQuery { CurrentQueryable = Interceptors.Where(t => t is INoSortInterceptor) .Cast() - .Aggregate(CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(prev)); + .Aggregate(CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(Criteria, prev)); CurrentQueryable = Interceptors.Where(t => t is INoSortInterceptor) .Cast>() - .Aggregate((IQueryable)CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(prev)); + .Aggregate((IQueryable)CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(Criteria, prev)); } diff --git a/README.md b/README.md index ca21b1f..358eb14 100644 --- a/README.md +++ b/README.md @@ -90,9 +90,9 @@ Interceptor | Interface IIncludeStrategyInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IIncludeStrategyInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/IncludeStrategyTests.cs) | This is to allow you to specify include paths for the queryable IIncludeStrategyInterceptor<T> | [interface](../master/PoweredSoft.DynamicQuery.Core/IIncludeStrategyInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/IncludeStrategyTests.cs#L65) | This is to allow you to specify include paths for the queryable IBeforeQueryFilterInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/BeforeFilterTests.cs) | Before adding the filters to the expression -IBeforeQueryFilterInterceptor<T> | [interface](../master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/BeforeFilterTests.cs#L39) | Before adding the filters to the expression -INoSortInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | This is called to allow you to specify an OrderBy in case none is specified, to avoid paging crash with EF6 -INoSortInterceptor<T> | [interface](../master/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | This is called to allow you to specify an OrderBy in case none is specified, to avoid paging crash with EF6 +IBeforeQueryFilterInterceptor<T> | [interface](../master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/BeforeFilterTests.cs#L64) | Before adding the filters to the expression +INoSortInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/NoSortTests.cs) | This is called to allow you to specify an OrderBy in case none is specified, to avoid paging crash with EF6 +INoSortInterceptor<T> | [interface](../master/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/NoSortTests.cs#L65) | This is called to allow you to specify an OrderBy in case none is specified, to avoid paging crash with EF6 > After/During expression building before query execution