No Sorting tests, made standard like all pre-expression building interceptors, passed down the criteria.
This commit is contained in:
parent
a6367894d4
commit
1fb58a9eb6
@ -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<T> : IQueryInterceptor
|
||||
{
|
||||
IQueryable<T> InterceptNoSort(IQueryable<T> queryable);
|
||||
IQueryable<T> InterceptNoSort(IQueryCriteria criteria, IQueryable<T> queryable);
|
||||
}
|
||||
}
|
||||
|
89
PoweredSoft.DynamicQuery.Test/NoSortTests.cs
Normal file
89
PoweredSoft.DynamicQuery.Test/NoSortTests.cs
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -153,11 +153,11 @@ namespace PoweredSoft.DynamicQuery
|
||||
{
|
||||
CurrentQueryable = Interceptors.Where(t => t is 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>)
|
||||
.Cast<INoSortInterceptor<T>>()
|
||||
.Aggregate((IQueryable<T>)CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(prev));
|
||||
.Aggregate((IQueryable<T>)CurrentQueryable, (prev, interceptor) => interceptor.InterceptNoSort(Criteria, prev));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user