include strategy testings.

This commit is contained in:
David Lebee 2018-10-23 17:08:32 -05:00
parent adb8ba06a6
commit 90197f46ba
2 changed files with 91 additions and 2 deletions

View File

@ -0,0 +1,89 @@
using Microsoft.EntityFrameworkCore;
using PoweredSoft.DynamicQuery.Core;
using PoweredSoft.DynamicQuery.Test.Mock;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
namespace PoweredSoft.DynamicQuery.Test
{
public class IncludeStrategyTests
{
private class MockIncludeStrategyInterceptor : IIncludeStrategyInterceptor
{
public IQueryable InterceptIncludeStrategy(IQueryCriteria criteria, IQueryable queryable)
{
queryable = ((IQueryable<Order>)queryable).Include(t => t.Customer);
return queryable;
}
}
private class MockIncludeStrategyGenericInterceptor :
IIncludeStrategyInterceptor<Order>,
IIncludeStrategyInterceptor<Customer>
{
public IQueryable<Order> InterceptIncludeStrategy(IQueryCriteria criteria, IQueryable<Order> queryable)
{
return queryable.Include(t => t.Customer);
}
public IQueryable<Customer> InterceptIncludeStrategy(IQueryCriteria criteria, IQueryable<Customer> queryable)
{
// should not go in here.
throw new NotImplementedException();
}
}
[Fact]
public void NonGeneric()
{
MockContextFactory.SeedAndTestContextFor("IncludeStrategyTests_NonGeneric", TestSeeders.SimpleSeedScenario, ctx =>
{
var criteria = new QueryCriteria();
var interceptor = new MockIncludeStrategyInterceptor();
// queryable of orders.
var queryable = ctx.Orders.AsQueryable();
// pass into the interceptor.
queryable = (IQueryable<Order>)interceptor.InterceptIncludeStrategy(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("IncludeStrategyTests_Generic", TestSeeders.SimpleSeedScenario, ctx =>
{
var criteria = new QueryCriteria();
var interceptor = new MockIncludeStrategyGenericInterceptor();
// queryable of orders.
var queryable = ctx.Orders.AsQueryable();
// pass into the interceptor.
queryable = interceptor.InterceptIncludeStrategy(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

@ -87,8 +87,8 @@ The following is documented in the order of what they are called by the **defaul
Interceptor | Interface | Example | Description Interceptor | Interface | Example | Description
---------------------------------------|--------------------------------------------------------------------------------------------|-------------------------------------------------------------|------------------------------------------------------------------------------------------------------------ ---------------------------------------|--------------------------------------------------------------------------------------------|-------------------------------------------------------------|------------------------------------------------------------------------------------------------------------
IIncludeStrategyInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IIncludeStrategyInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | 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/TBT.md) | 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 | [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&lt;T&gt; | [interface](../master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | 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/TBT.md) | This is called to allow you to specify an OrderBy in case none is specified, to avoid paging crash with EF6