-
Notifications
You must be signed in to change notification settings - Fork 7
/
GroupInterceptorTests.cs
76 lines (69 loc) · 2.89 KB
/
GroupInterceptorTests.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
using Microsoft.EntityFrameworkCore;
using PoweredSoft.DynamicQuery.Core;
using PoweredSoft.DynamicQuery.Extensions;
using PoweredSoft.DynamicQuery.Test.Mock;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
namespace PoweredSoft.DynamicQuery.Test
{
public partial class GroupInterceptorTests
{
private class MockGroupInterceptor : IGroupInterceptor
{
public IGroup InterceptGroup(IGroup group)
{
return new Group()
{
Path = "Customer.FirstName"
};
}
}
[Fact]
public void Simple()
{
MockContextFactory.SeedAndTestContextFor("GroupInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
{
var expected = ctx.Orders
.OrderBy(t => t.Customer.FirstName)
.GroupBy(t => t.Customer.FirstName)
.Select(t => t.Key)
.ToList();
var criteria = new QueryCriteria();
criteria.Groups.Add(new Group { Path = "CustomerFirstName" });
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
queryHandler.AddInterceptor(new MockGroupInterceptor());
var result = queryHandler.Execute(ctx.Orders.Include(t => t.Customer), criteria, new QueryExecutionOptions
{
GroupByInMemory = true
});
var groupedResult = result.GroupedResult();
var actual = groupedResult.Groups.Select(t => t.GroupValue).ToList();
Assert.Equal(expected, actual);
});
}
[Fact]
public void WithInterptorSimple()
{
MockContextFactory.SeedAndTestContextFor("GroupInterceptorTests_WithInterptorSimple", TestSeeders.SimpleSeedScenario, ctx =>
{
var expected = ctx.Orders
.OrderBy(t => t.Customer.FirstName)
.GroupBy(t => t.Customer.FirstName)
.Select(t => t.Key)
.ToList();
var criteria = new QueryCriteria();
criteria.Groups.Add(new Group { Path = "CustomerFirstName" });
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
queryHandler.AddInterceptor(new MockGroupInterceptor());
queryHandler.AddInterceptor(new MockQueryExecutionOptionsInterceptor());
var result = queryHandler.Execute(ctx.Orders.Include(t => t.Customer), criteria);
var groupedResult = result.GroupedResult();
var actual = groupedResult.Groups.Select(t => t.GroupValue).ToList();
Assert.Equal(expected, actual);
});
}
}
}