aggregate testings.
This commit is contained in:
parent
49029d535f
commit
18540a672d
45
PoweredSoft.DynamicQuery.Test/AggregateInterceptorTests.cs
Normal file
45
PoweredSoft.DynamicQuery.Test/AggregateInterceptorTests.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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 = "Item.Price",
|
||||||
|
Type = AggregateType.Avg
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Simple()
|
||||||
|
{
|
||||||
|
MockContextFactory.SeedAndTestContextFor("AggregatorInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
|
||||||
|
{
|
||||||
|
var expected = ctx.OrderItems.GroupBy(t => true).Select(t => new
|
||||||
|
{
|
||||||
|
PriceAtTheTime = t.Average(t2 => t2.Item.Price)
|
||||||
|
}).First();
|
||||||
|
|
||||||
|
var criteria = new QueryCriteria();
|
||||||
|
criteria.Aggregates.Add(new Aggregate
|
||||||
|
{
|
||||||
|
Type = AggregateType.Avg,
|
||||||
|
Path = "ItemPrice"
|
||||||
|
});
|
||||||
|
var queryHandler = new QueryHandler();
|
||||||
|
queryHandler.AddInterceptor(new MockAggregateInterceptor());
|
||||||
|
var result = queryHandler.Execute(ctx.OrderItems, criteria);
|
||||||
|
Assert.Equal(expected.PriceAtTheTime, result.Aggregates.First().Value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user