No Sorting tests, made standard like all pre-expression building interceptors, passed down the criteria.

This commit is contained in:
David Lebee 2018-10-23 17:42:53 -05:00
parent a6367894d4
commit 1fb58a9eb6
4 changed files with 96 additions and 7 deletions

View File

@ -4,11 +4,11 @@ namespace PoweredSoft.DynamicQuery.Core
{ {
public interface INoSortInterceptor : IQueryInterceptor public interface INoSortInterceptor : IQueryInterceptor
{ {
IQueryable InterceptNoSort(IQueryable queryable); IQueryable InterceptNoSort(IQueryCriteria criteria, IQueryable queryable);
} }
public interface INoSortInterceptor<T> : IQueryInterceptor public interface INoSortInterceptor<T> : IQueryInterceptor
{ {
IQueryable<T> InterceptNoSort(IQueryable<T> queryable); IQueryable<T> InterceptNoSort(IQueryCriteria criteria, IQueryable<T> queryable);
} }
} }

View File

@ -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<Order>,
INoSortInterceptor<Customer>
{
public IQueryable<Order> InterceptNoSort(IQueryCriteria criteria, IQueryable<Order> queryable)
{
return queryable.OrderBy(t => t.Customer.LastName);
}
public IQueryable<Customer> InterceptNoSort(IQueryCriteria criteria, IQueryable<Customer> 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<Order>)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);
});
}
}
}

View File

@ -153,11 +153,11 @@ namespace PoweredSoft.DynamicQuery
{ {
CurrentQueryable = Interceptors.Where(t => t is INoSortInterceptor) CurrentQueryable = Interceptors.Where(t => t is INoSortInterceptor)
.Cast<INoSortInterceptor>() .Cast<INoSortInterceptor>()
.Aggregate(CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(prev)); .Aggregate(CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(Criteria, prev));
CurrentQueryable = Interceptors.Where(t => t is INoSortInterceptor<T>) CurrentQueryable = Interceptors.Where(t => t is INoSortInterceptor<T>)
.Cast<INoSortInterceptor<T>>() .Cast<INoSortInterceptor<T>>()
.Aggregate((IQueryable<T>)CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(prev)); .Aggregate((IQueryable<T>)CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(Criteria, prev));
} }

View File

@ -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 | [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&lt;T&gt; | [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 IIncludeStrategyInterceptor&lt;T&gt; | [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 | [interface](../master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/BeforeFilterTests.cs) | Before adding the filters to the expression
IBeforeQueryFilterInterceptor&lt;T&gt; | [interface](../master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/BeforeFilterTests.cs#L39) | Before adding the filters to the expression IBeforeQueryFilterInterceptor&lt;T&gt; | [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/TBT.md) | This is called to allow you to specify an OrderBy in case none is specified, to avoid paging crash with EF6 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&lt;T&gt; | [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&lt;T&gt; | [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 > After/During expression building before query execution