before filter testing.

This commit is contained in:
David Lebee 2018-10-23 17:21:01 -05:00
parent 90197f46ba
commit a6367894d4
2 changed files with 90 additions and 2 deletions

View File

@ -0,0 +1,88 @@
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 BeforeFilterTests
{
private class MockBeforeQueryFilterInterceptor : IBeforeQueryFilterInterceptor
{
public IQueryable InterceptBeforeFiltering(IQueryCriteria criteria, IQueryable queryable)
{
return queryable.Where(t => t.Equal("Customer.FirstName", "David"));
}
}
private class MockBeforeQueryFilterGenericInterceptor :
IBeforeQueryFilterInterceptor<Order>,
IBeforeQueryFilterInterceptor<Customer>
{
public IQueryable<Order> InterceptBeforeFiltering(IQueryCriteria criteria, IQueryable<Order> queryable)
{
return queryable.Where(t => t.Customer.FirstName == "David");
}
public IQueryable<Customer> InterceptBeforeFiltering(IQueryCriteria criteria, IQueryable<Customer> queryable)
{
// leave throw it validates the test, if it gets in here it shoulnd't
throw new NotImplementedException();
}
}
[Fact]
public void NonGeneric()
{
MockContextFactory.SeedAndTestContextFor("BeforeFilterTests_NonGeneric", TestSeeders.SimpleSeedScenario, ctx =>
{
var criteria = new QueryCriteria();
var interceptor = new MockBeforeQueryFilterInterceptor();
// queryable of orders.
var queryable = ctx.Orders.AsQueryable();
// pass into the interceptor.
queryable = (IQueryable<Order>)interceptor.InterceptBeforeFiltering(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("BeforeFilterTests_Generic", TestSeeders.SimpleSeedScenario, ctx =>
{
var criteria = new QueryCriteria();
var interceptor = new MockBeforeQueryFilterGenericInterceptor();
// queryable of orders.
var queryable = ctx.Orders.AsQueryable();
// pass into the interceptor.
queryable = interceptor.InterceptBeforeFiltering(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

@ -89,8 +89,8 @@ 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&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/TBT.md) | Before adding the filters to the expression
IBeforeQueryFilterInterceptor&lt;T&gt; | [interface](../master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | 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
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&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