forked from PoweredSoft/DynamicQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AggregateInterceptorTests.cs
48 lines (45 loc) · 1.59 KB
/
AggregateInterceptorTests.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
using Microsoft.EntityFrameworkCore;
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 AggregateInterceptorTests
{
private class MockAggregateInterceptor : IAggregateInterceptor
{
public IAggregate InterceptAggregate(IAggregate aggregate) => new Aggregate
{
Path = "Price",
Type = AggregateType.Avg
};
}
[Fact]
public void Simple()
{
MockContextFactory.SeedAndTestContextFor("AggregatorInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
{
var expected = ctx.Items
.GroupBy(t => true)
.Select(t => new
{
PriceAtTheTime = t.Average(t2 => t2.Price)
}).First();
var criteria = new QueryCriteria();
criteria.Aggregates.Add(new Aggregate
{
Type = AggregateType.Avg,
Path = "ItemPrice"
});
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
queryHandler.AddInterceptor(new MockAggregateInterceptor());
var result = queryHandler.Execute(ctx.Items, criteria);
Assert.Equal(expected.PriceAtTheTime, result.Aggregates.First().Value);
});
}
}
}