dotnet-dynamic-query/PoweredSoft.DynamicQuery.Test/SortInterceptorTests.cs
2018-10-23 21:07:39 -05:00

44 lines
1.4 KiB
C#

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"));
var queryHandler = new QueryHandler();
queryHandler.AddInterceptor(new MockSortInterceptor());
var result = queryHandler.Execute(ctx.Orders, criteria);
Assert.Equal(expected, result.Data);
});
}
}
}