include strategy testings.
This commit is contained in:
parent
adb8ba06a6
commit
90197f46ba
89
PoweredSoft.DynamicQuery.Test/IncludeStrategyTests.cs
Normal file
89
PoweredSoft.DynamicQuery.Test/IncludeStrategyTests.cs
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -87,8 +87,8 @@ The following is documented in the order of what they are called by the **defaul
|
||||
|
||||
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<T> | [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<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/TBT.md) | Before adding the filters to the expression
|
||||
IBeforeQueryFilterInterceptor<T> | [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
|
||||
|
Loading…
Reference in New Issue
Block a user