-
Notifications
You must be signed in to change notification settings - Fork 7
/
NoSortTests.cs
89 lines (76 loc) · 3.16 KB
/
NoSortTests.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
using Microsoft.EntityFrameworkCore;
using PoweredSoft.DynamicQuery.Core;
using PoweredSoft.DynamicQuery.Test.Mock;
using PoweredSoft.DynamicLinq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
namespace PoweredSoft.DynamicQuery.Test
{
public class NoSortTests
{
private class MockNoSortInterceptor : INoSortInterceptor
{
public IQueryable InterceptNoSort(IQueryCriteria criteria, IQueryable queryable)
{
return queryable.OrderBy("Customer.LastName");
}
}
private class MockNoSortGenericInterceptor :
INoSortInterceptor<Order>,
INoSortInterceptor<Customer>
{
public IQueryable<Order> InterceptNoSort(IQueryCriteria criteria, IQueryable<Order> queryable)
{
return queryable.OrderBy(t => t.Customer.LastName);
}
public IQueryable<Customer> InterceptNoSort(IQueryCriteria criteria, IQueryable<Customer> queryable)
{
// should not go in here.
throw new NotImplementedException();
}
}
[Fact]
public void NonGeneric()
{
MockContextFactory.SeedAndTestContextFor("NoSortTests_NonGeneric", TestSeeders.SimpleSeedScenario, ctx =>
{
var criteria = new QueryCriteria();
var interceptor = new MockNoSortInterceptor();
// queryable of orders.
var queryable = ctx.Orders.AsQueryable();
// pass into the interceptor.
queryable = (IQueryable<Order>)interceptor.InterceptNoSort(criteria, queryable);
// query handler should pass by the same interceptor.
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
queryHandler.AddInterceptor(interceptor);
var result = queryHandler.Execute(ctx.Orders, criteria);
// compare results.
var expected = queryable.ToList();
Assert.Equal(expected, result.Data);
});
}
[Fact]
public void Generic()
{
MockContextFactory.SeedAndTestContextFor("NoSortTests_Generic", TestSeeders.SimpleSeedScenario, ctx =>
{
var criteria = new QueryCriteria();
var interceptor = new MockNoSortGenericInterceptor();
// queryable of orders.
var queryable = ctx.Orders.AsQueryable();
// pass into the interceptor.
queryable = interceptor.InterceptNoSort(criteria, queryable);
// query handler should pass by the same interceptor.
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
queryHandler.AddInterceptor(interceptor);
var result = queryHandler.Execute(ctx.Orders, criteria);
// compare results.
var expected = queryable.ToList();
Assert.Equal(expected, result.Data);
});
}
}
}