Skip to content

Commit 17e9434

Browse files
author
David Lebee
committed
Merge branch 'release/2.x-ready'
2 parents 61642ee + ec6a2e1 commit 17e9434

18 files changed

+343
-180
lines changed

PoweredSoft.DynamicQuery.AspNetCore/PoweredSoft.DynamicQuery.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RepositoryUrl>https://github.com/PoweredSoft/DynamicQuery</RepositoryUrl>
99
<RepositoryType>github</RepositoryType>
1010
<PackageTags>powered,soft,dynamic,criteria,query,builder,asp,net,core</PackageTags>
11-
<Version>1.0.0$(VersionSuffix)</Version>
11+
<Version>2.0.0$(VersionSuffix)</Version>
1212
<PackageIconUrl>https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&amp;amp;r=g&amp;amp;d=retro</PackageIconUrl>
1313
<Product>PoweredSoft.DynamicQuery.AspNetCore</Product>
1414
<Description>This projects makes it easier to use dynamic query in a asp.net core mvc project.</Description>

PoweredSoft.DynamicQuery.Core/IAfterReadInterceptor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ public interface IAfterReadInterceptorAsync<T> : IQueryInterceptor
2424
{
2525
Task AfterReadAsync(List<Tuple<T, object>> pairs, CancellationToken cancellationToken = default(CancellationToken));
2626
}
27+
28+
public interface IAfterReadInterceptor<T, T2> : IQueryInterceptor
29+
{
30+
void AfterRead(List<Tuple<T, T2>> pairs);
31+
}
32+
33+
public interface IAfterReadInterceptorAsync<T, T2> : IQueryInterceptor
34+
{
35+
Task AfterReadAsync(List<Tuple<T, T2>> pairs, CancellationToken cancellationToken = default(CancellationToken));
36+
}
2737
}

PoweredSoft.DynamicQuery.Core/IQueryConvertInterceptor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public interface IQueryConvertInterceptor<T> : IQueryInterceptor
1313
{
1414
object InterceptResultTo(T entity);
1515
}
16+
17+
public interface IQueryConvertInterceptor<T, T2> : IQueryInterceptor
18+
{
19+
T2 InterceptResultTo(T entity);
20+
}
1621
}

PoweredSoft.DynamicQuery.Core/IQueryHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ public interface IInterceptableQueryHandler
1313

1414
public interface IQueryHandler : IInterceptableQueryHandler
1515
{
16-
IQueryExecutionResult Execute(IQueryable queryable, IQueryCriteria criteria);
16+
IQueryExecutionResult<TSource> Execute<TSource>(IQueryable<TSource> queryable, IQueryCriteria criteria);
17+
IQueryExecutionResult<TRecord> Execute<TSource, TRecord>(IQueryable<TSource> queryable, IQueryCriteria criteria);
1718
}
1819

1920
public interface IQueryHandlerAsync : IInterceptableQueryHandler
2021
{
21-
Task<IQueryExecutionResult> ExecuteAsync(IQueryable queryable, IQueryCriteria criteria, CancellationToken cancellationToken = default(CancellationToken));
22+
Task<IQueryExecutionResult<TSource>> ExecuteAsync<TSource>(IQueryable<TSource> queryable, IQueryCriteria criteria, CancellationToken cancellationToken = default(CancellationToken));
23+
Task<IQueryExecutionResult<TRecord>> ExecuteAsync<TSource, TRecord>(IQueryable<TSource> queryable, IQueryCriteria criteria, CancellationToken cancellationToken = default(CancellationToken));
2224
}
2325
}

PoweredSoft.DynamicQuery.Core/IQueryResult.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,35 @@ public interface IAggregateResult
1111
object Value { get; set; }
1212
}
1313

14-
public interface IQueryResult
14+
public interface IQueryResult<TRecord>
1515
{
1616
List<IAggregateResult> Aggregates { get; }
17-
List<object> Data { get; }
17+
List<TRecord> Data { get; }
1818
}
1919

20-
public interface IGroupQueryResult : IQueryResult
20+
public interface IGroupQueryResult<TRecord> : IQueryResult<TRecord>
2121
{
2222
string GroupPath { get; set; }
2323
object GroupValue { get; set; }
24+
bool HasSubGroups { get; }
25+
List<IGroupQueryResult<TRecord>> SubGroups { get; set; }
2426
}
2527

26-
public interface IQueryExecutionResult : IQueryResult
28+
public interface IQueryExecutionResultPaging
2729
{
2830
long TotalRecords { get; set; }
2931
long? NumberOfPages { get; set; }
3032
}
3133

32-
34+
public interface IQueryExecutionResult<TRecord> : IQueryResult<TRecord>, IQueryExecutionResultPaging
35+
{
36+
37+
}
38+
39+
public interface IQueryExecutionGroupResult<TRecord> : IQueryExecutionResult<TRecord>
40+
{
41+
List<IGroupQueryResult<TRecord>> Groups { get; set; }
42+
}
43+
44+
3345
}

PoweredSoft.DynamicQuery.Core/PoweredSoft.DynamicQuery.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RepositoryUrl>https://github.com/PoweredSoft/DynamicQuery.Core/</RepositoryUrl>
99
<RepositoryType>github</RepositoryType>
1010
<PackageTags>powered,soft,dynamic,criteria,query,builder</PackageTags>
11-
<Version>1.0.0$(VersionSuffix)</Version>
11+
<Version>2.0.0$(VersionSuffix)</Version>
1212
<PackageIconUrl>https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&amp;amp;r=g&amp;amp;d=retro</PackageIconUrl>
1313
<Product>PoweredSoft.DynamicQuery.Core</Product>
1414
<Description>core abstractions</Description>

PoweredSoft.DynamicQuery.Test/AggregateTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public void WithGrouping()
114114

115115
var queryHandler = new QueryHandler();
116116
var result = queryHandler.Execute(ctx.OrderItems, criteria);
117-
var groups = result.Data.Cast<IGroupQueryResult>().ToList();
117+
118+
var groupedResult = result as IQueryExecutionGroupResult<OrderItem>;
119+
Assert.NotNull(groupedResult);
120+
121+
var groups = groupedResult.Groups;
118122

119123
// validate group and aggregates of groups.
120124
Assert.Equal(groups.Count, shouldResults.Count);

PoweredSoft.DynamicQuery.Test/AsyncTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using PoweredSoft.Data;
22
using PoweredSoft.Data.EntityFrameworkCore;
33
using PoweredSoft.DynamicQuery.Core;
4+
using PoweredSoft.DynamicQuery.Extensions;
45
using PoweredSoft.DynamicQuery.Test.Mock;
56
using System;
67
using System.Collections.Generic;
@@ -65,7 +66,7 @@ public void WithGrouping()
6566
var asyncService = new AsyncQueryableService(new[] { new AsyncQueryableHandlerService() });
6667
var queryHandler = new QueryHandlerAsync(asyncService);
6768
var result = await queryHandler.ExecuteAsync(ctx.OrderItems, criteria);
68-
var groups = result.Data.Cast<IGroupQueryResult>().ToList();
69+
var groups = result.GroupedResult().Groups;
6970

7071
// validate group and aggregates of groups.
7172
Assert.Equal(groups.Count, shouldResults.Count);

PoweredSoft.DynamicQuery.Test/ConvertibleInterceptorTests.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ public object InterceptResultTo(Order entity)
5555
}
5656
}
5757

58+
private class MockQueryConvertGenericInterceptor2 :
59+
IQueryConvertInterceptor<Customer, CustomerModel>
60+
{
61+
public CustomerModel InterceptResultTo(Customer entity)
62+
{
63+
var customer = entity;
64+
var personModel = new CustomerModel
65+
{
66+
Id = customer.Id,
67+
FirstName = customer.FirstName,
68+
LastName = customer.LastName
69+
};
70+
return personModel;
71+
}
72+
}
73+
5874
[Fact]
5975
public void NonGeneric()
6076
{
@@ -63,7 +79,7 @@ public void NonGeneric()
6379
var criteria = new QueryCriteria();
6480
var queryHandler = new QueryHandler();
6581
queryHandler.AddInterceptor(new MockQueryConvertInterceptor());
66-
var result = queryHandler.Execute(ctx.Customers, criteria);
82+
var result = queryHandler.Execute<Customer, CustomerModel>(ctx.Customers, criteria);
6783
Assert.All(result.Data, t => Assert.IsType<CustomerModel>(t));
6884
});
6985
}
@@ -76,7 +92,20 @@ public void Generic()
7692
var criteria = new QueryCriteria();
7793
var queryHandler = new QueryHandler();
7894
queryHandler.AddInterceptor(new MockQueryConvertGenericInterceptor());
79-
var result = queryHandler.Execute(ctx.Customers, criteria);
95+
var result = queryHandler.Execute<Customer, CustomerModel>(ctx.Customers, criteria);
96+
Assert.All(result.Data, t => Assert.IsType<CustomerModel>(t));
97+
});
98+
}
99+
100+
[Fact]
101+
public void Generic2()
102+
{
103+
MockContextFactory.SeedAndTestContextFor("ConvertibleIntereceptorTests_Generic2", TestSeeders.SimpleSeedScenario, ctx =>
104+
{
105+
var criteria = new QueryCriteria();
106+
var queryHandler = new QueryHandler();
107+
queryHandler.AddInterceptor(new MockQueryConvertGenericInterceptor2());
108+
var result = queryHandler.Execute<Customer, CustomerModel>(ctx.Customers, criteria);
80109
Assert.All(result.Data, t => Assert.IsType<CustomerModel>(t));
81110
});
82111
}

PoweredSoft.DynamicQuery.Test/GroupInterceptorTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using PoweredSoft.DynamicQuery.Core;
2+
using PoweredSoft.DynamicQuery.Extensions;
23
using PoweredSoft.DynamicQuery.Test.Mock;
34
using System;
45
using System.Collections.Generic;
@@ -37,7 +38,9 @@ public void Simple()
3738
var queryHandler = new QueryHandler();
3839
queryHandler.AddInterceptor(new MockGroupInterceptor());
3940
var result = queryHandler.Execute(ctx.Orders, criteria);
40-
var actual = result.Data.Cast<IGroupQueryResult>().Select(t => t.GroupValue).ToList();
41+
42+
var groupedResult = result.GroupedResult();
43+
var actual = groupedResult.Groups.Select(t => t.GroupValue).ToList();
4144
Assert.Equal(expected, actual);
4245
});
4346
}

0 commit comments

Comments
 (0)