From 486200ea6c068bd7ce05fa85404c6628384c697b Mon Sep 17 00:00:00 2001 From: David Lebee Date: Tue, 23 Oct 2018 21:07:39 -0500 Subject: [PATCH] sort interceptors. --- .../SortInterceptorTests.cs | 43 +++++++++++++++++++ README.md | 4 +- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 PoweredSoft.DynamicQuery.Test/SortInterceptorTests.cs diff --git a/PoweredSoft.DynamicQuery.Test/SortInterceptorTests.cs b/PoweredSoft.DynamicQuery.Test/SortInterceptorTests.cs new file mode 100644 index 0000000..9217f22 --- /dev/null +++ b/PoweredSoft.DynamicQuery.Test/SortInterceptorTests.cs @@ -0,0 +1,43 @@ +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 SortInterceptorTests + { + private class MockSortInterceptor : ISortInterceptor + { + public IEnumerable InterceptSort(IEnumerable sort) + { + return new Sort[] + { + new Sort("Customer.FirstName"), + new Sort("Customer.LastName") + }; + } + } + + [Fact] + public void Simple() + { + MockContextFactory.SeedAndTestContextFor("SortInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx => + { + // expected + var expected = ctx.Orders.OrderBy(t => t.Customer.FirstName).ThenBy(t => t.Customer.LastName).ToList(); + + // criteria + var criteria = new QueryCriteria(); + criteria.Sorts.Add(new Sort("CustomerFullName")); + var queryHandler = new QueryHandler(); + queryHandler.AddInterceptor(new MockSortInterceptor()); + var result = queryHandler.Execute(ctx.Orders, criteria); + Assert.Equal(expected, result.Data); + }); + } + } +} diff --git a/README.md b/README.md index 358eb14..9662368 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,8 @@ INoSortInterceptor<T> | [interface](../master/PoweredSoft.Dynam Interceptor | Interface | Example | Description ----------------------|------------------------------------------------------------------------------------|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------- -IFilterInterceptor | [interface](../master/PoweredSoft.DynamicQuery.Core/IFilterInterceptor.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | 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/TBT.md) | This interceptor allows you to change the behavior of a ISort 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 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 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