forked from PoweredSoft/DynamicQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortTests.cs
93 lines (82 loc) · 3.28 KB
/
SortTests.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PoweredSoft.DynamicLinq;
using PoweredSoft.DynamicQuery.Core;
using PoweredSoft.DynamicQuery.Test.Mock;
using Xunit;
namespace PoweredSoft.DynamicQuery.Test
{
public class SortTests
{
[Fact]
public void Simple()
{
MockContextFactory.SeedAndTestContextFor("SortTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
{
var shouldResult = ctx.Orders.OrderBy(t => t.OrderNum).ToList();
// query handler that is empty should be the same as running to list.
var criteria = new QueryCriteria()
{
Sorts = new List<ISort>()
{
new Sort("OrderNum")
}
};
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
var result = queryHandler.Execute(ctx.Orders, criteria);
Assert.Equal(shouldResult, result.Data);
});
}
[Fact]
public void MultiSort()
{
MockContextFactory.SeedAndTestContextFor("SortTests_MultiSort", TestSeeders.SimpleSeedScenario, ctx =>
{
var shouldResult = ctx.Orders.OrderBy(t => t.Customer.FirstName).ThenBy(t => t.OrderNum).ToList();
// query handler that is empty should be the same as running to list.
var criteria = new QueryCriteria()
{
Sorts = new List<ISort>()
{
new Sort("Customer.FirstName"),
new Sort("OrderNum")
}
};
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
var result = queryHandler.Execute(ctx.Orders, criteria);
Assert.Equal(shouldResult, result.Data);
});
}
private class MockSortInterceptor : ISortInterceptor
{
public IEnumerable<ISort> InterceptSort(IEnumerable<ISort> sort)
{
if (sort.Count() == 1 && sort.First().Path == "OrderNumStr")
return new ISort[] { new Sort("OrderNum", false) };
return sort;
}
}
[Fact]
public void SortInterceptor()
{
MockContextFactory.SeedAndTestContextFor("SortTests_SortInterceptor", TestSeeders.SimpleSeedScenario, ctx =>
{
var shouldResult = ctx.Orders.OrderByDescending(t => t.OrderNum).ToList();
// query handler that is empty should be the same as running to list.
var criteria = new QueryCriteria()
{
Sorts = new List<ISort>()
{
new Sort("OrderNumStr", false)
}
};
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
queryHandler.AddInterceptor(new MockSortInterceptor());
var result = queryHandler.Execute(ctx.Orders, criteria);
Assert.Equal(shouldResult, result.Data);
});
}
}
}