2018-10-23 22:07:39 -04:00
|
|
|
|
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<ISort> InterceptSort(IEnumerable<ISort> 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"));
|
2019-12-12 18:37:32 -05:00
|
|
|
|
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
|
2018-10-23 22:07:39 -04:00
|
|
|
|
queryHandler.AddInterceptor(new MockSortInterceptor());
|
|
|
|
|
var result = queryHandler.Execute(ctx.Orders, criteria);
|
|
|
|
|
Assert.Equal(expected, result.Data);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|