forked from PoweredSoft/DynamicQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortInterceptorTests.cs
43 lines (40 loc) · 1.41 KB
/
SortInterceptorTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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<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(Enumerable.Empty<IQueryInterceptorProvider>());
queryHandler.AddInterceptor(new MockSortInterceptor());
var result = queryHandler.Execute(ctx.Orders, criteria);
Assert.Equal(expected, result.Data);
});
}
}
}