grouping interceptor tests.
This commit is contained in:
parent
486200ea6c
commit
49029d535f
@ -1,6 +1,6 @@
|
|||||||
namespace PoweredSoft.DynamicQuery.Core
|
namespace PoweredSoft.DynamicQuery.Core
|
||||||
{
|
{
|
||||||
public interface IGroupingInterceptor : IQueryInterceptor
|
public interface IGroupInterceptor : IQueryInterceptor
|
||||||
{
|
{
|
||||||
IGroup InterceptGroup(IGroup group);
|
IGroup InterceptGroup(IGroup group);
|
||||||
}
|
}
|
||||||
|
45
PoweredSoft.DynamicQuery.Test/GroupInterceptorTests.cs
Normal file
45
PoweredSoft.DynamicQuery.Test/GroupInterceptorTests.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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 GroupInterceptorTests
|
||||||
|
{
|
||||||
|
private class MockGroupInterceptor : IGroupInterceptor
|
||||||
|
{
|
||||||
|
public IGroup InterceptGroup(IGroup group)
|
||||||
|
{
|
||||||
|
return new Group()
|
||||||
|
{
|
||||||
|
Path = "Customer.FirstName"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Simple()
|
||||||
|
{
|
||||||
|
MockContextFactory.SeedAndTestContextFor("GroupInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
|
||||||
|
{
|
||||||
|
var expected = ctx.Orders
|
||||||
|
.OrderBy(t => t.Customer.FirstName)
|
||||||
|
.GroupBy(t => t.Customer.FirstName)
|
||||||
|
.Select(t => t.Key)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var criteria = new QueryCriteria();
|
||||||
|
criteria.Groups.Add(new Group { Path = "CustomerFirstName" });
|
||||||
|
var queryHandler = new QueryHandler();
|
||||||
|
queryHandler.AddInterceptor(new MockGroupInterceptor());
|
||||||
|
var result = queryHandler.Execute(ctx.Orders, criteria);
|
||||||
|
var actual = result.Data.Cast<IGroupQueryResult>().Select(t => t.GroupValue).ToList();
|
||||||
|
Assert.Equal(expected, actual);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -42,8 +42,8 @@ namespace PoweredSoft.DynamicQuery
|
|||||||
protected virtual IGroup InterceptGroup<T>(IGroup group)
|
protected virtual IGroup InterceptGroup<T>(IGroup group)
|
||||||
{
|
{
|
||||||
var ret = Interceptors
|
var ret = Interceptors
|
||||||
.Where(t => t is IGroupingInterceptor)
|
.Where(t => t is IGroupInterceptor)
|
||||||
.Cast<IGroupingInterceptor>()
|
.Cast<IGroupInterceptor>()
|
||||||
.Aggregate(group, (prev, inter) => inter.InterceptGroup(prev));
|
.Aggregate(group, (prev, inter) => inter.InterceptGroup(prev));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -100,8 +100,8 @@ Interceptor | Interface
|
|||||||
----------------------|------------------------------------------------------------------------------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------
|
----------------------|------------------------------------------------------------------------------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------
|
||||||
IFilterInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/FilterInterceptorTests.cs) | This interceptor allows you to change the behavior of a IFilter being applied to the queryable
|
IFilterInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/FilterInterceptorTests.cs) | This interceptor allows you to change the behavior of a IFilter being applied to the queryable
|
||||||
ISortInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/ISortInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/SortInterceptorTests.cs) | This interceptor allows you to change the behavior of a ISort being applied to the queryable
|
ISortInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/ISortInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/SortInterceptorTests.cs) | This interceptor allows you to change the behavior of a ISort being applied to the queryable
|
||||||
IGroupInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IGroupInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to change the behavior of a IGroup being applied to the queryable
|
IGroupInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IGroupInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/GroupInterceptorTests.cs) | This interceptor allows you to change the behavior of a IGroup being applied to the queryable
|
||||||
IAggregateInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IAggregateInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to change the behavior of a IAggregate being applied to the queryable
|
IAggregateInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IAggregateInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/AggregateInterceptorTests.cs) | This interceptor allows you to change the behavior of a IAggregate being applied to the queryable
|
||||||
|
|
||||||
> Post Query execution
|
> Post Query execution
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user