Skip to content

Commit 9ea5a4f

Browse files
Support Skip/Take with single-level grouping (#404)
1 parent 63aa2c1 commit 9ea5a4f

File tree

22 files changed

+701
-60
lines changed

22 files changed

+701
-60
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using DevExtreme.AspNet.Data.ResponseModel;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using Xunit;
7+
8+
namespace DevExtreme.AspNet.Data.Tests {
9+
10+
public class RemoteGroupCountTestHelper {
11+
12+
public interface IEntity {
13+
int G1 { get; set; }
14+
int G2 { get; set; }
15+
}
16+
17+
public static IEnumerable<T> GenerateTestData<T>(Func<T> itemFactory) where T : IEntity {
18+
T CreateItem(int g1, int g2) {
19+
var item = itemFactory();
20+
item.G1 = g1;
21+
item.G2 = g2;
22+
return item;
23+
}
24+
yield return CreateItem(1, 0);
25+
yield return CreateItem(2, 1);
26+
yield return CreateItem(2, 1);
27+
yield return CreateItem(2, 2);
28+
yield return CreateItem(3, 0);
29+
}
30+
31+
public static void Run<T>(IQueryable<T> data) {
32+
Run(data, new[] {
33+
new GroupingInfo { Selector = "G1", IsExpanded = false }
34+
});
35+
Run(data, new[] {
36+
new GroupingInfo { Selector = "G1", IsExpanded = false },
37+
new GroupingInfo { Selector = "G2", IsExpanded = false }
38+
});
39+
}
40+
41+
static void Run<T>(IQueryable<T> data, GroupingInfo[] group) {
42+
var loadOptions = new SampleLoadOptions {
43+
RemoteGrouping = true,
44+
RequireTotalCount = false,
45+
RequireGroupCount = true,
46+
Group = group,
47+
Skip = 1,
48+
Take = 1
49+
};
50+
51+
var loadResult = DataSourceLoader.Load(data, loadOptions);
52+
Assert.Equal(3, loadResult.groupCount);
53+
54+
var log = loadOptions.ExpressionLog;
55+
56+
if(group.Length == 1) {
57+
Assert.Equal(-1, loadResult.totalCount); // not requested
58+
Assert.Equal(2, log.Count);
59+
Assert.Contains(log, line => line.Contains(".Distinct().Count()"));
60+
} else {
61+
Assert.Equal(data.Count(), loadResult.totalCount); // bonus because all groups are loaded
62+
Assert.Single(log);
63+
}
64+
}
65+
}
66+
67+
}

net/DevExtreme.AspNet.Data.Tests.EF6/DevExtreme.AspNet.Data.Tests.EF6.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<Compile Include="Bug239.cs" />
8888
<Compile Include="Bug240.cs" />
8989
<Compile Include="ExpandLinqSumType.cs" />
90+
<Compile Include="RemoteGroupCount.cs" />
9091
<Compile Include="PaginateViaPrimaryKey.cs" />
9192
<Compile Include="RemoteGroupingStress.cs" />
9293
<Compile Include="Summary.cs" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Xunit;
4+
5+
namespace DevExtreme.AspNet.Data.Tests.EF6 {
6+
using DataItem = RemoteGroupCount_DataItem;
7+
8+
public class RemoteGroupCount_DataItem : RemoteGroupCountTestHelper.IEntity {
9+
public int ID { get; set; }
10+
public int G1 { get; set; }
11+
public int G2 { get; set; }
12+
}
13+
14+
public class RemoteGroupCount {
15+
16+
[Fact]
17+
public async Task Scenario() {
18+
await TestDbContext.ExecAsync(context => {
19+
var dbSet = context.Set<DataItem>();
20+
21+
dbSet.AddRange(RemoteGroupCountTestHelper.GenerateTestData(() => new DataItem()));
22+
context.SaveChanges();
23+
24+
RemoteGroupCountTestHelper.Run(dbSet);
25+
});
26+
}
27+
28+
}
29+
30+
}

net/DevExtreme.AspNet.Data.Tests.EF6/TestDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder) {
3434
modelBuilder.Entity<PaginateViaPrimaryKey_DataItem>().HasKey(i => new { i.K1, i.K2 });
3535
modelBuilder.Entity<Async_DataItem>();
3636
modelBuilder.Entity<ExpandLinqSumType_DataItem>();
37+
modelBuilder.Entity<RemoteGroupCount_DataItem>();
3738
}
3839

3940
public static async Task ExecAsync(Func<TestDbContext, Task> action) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#if !EFCORE1
2+
using System;
3+
using System.ComponentModel.DataAnnotations.Schema;
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace DevExtreme.AspNet.Data.Tests.EFCore {
8+
9+
public class RemoteGroupCount {
10+
11+
[Table(nameof(RemoteGroupCount) + "_" + nameof(DataItem))]
12+
public class DataItem : RemoteGroupCountTestHelper.IEntity {
13+
public int ID { get; set; }
14+
public int G1 { get; set; }
15+
public int G2 { get; set; }
16+
}
17+
18+
[Fact]
19+
public async Task Scenario() {
20+
await TestDbContext.ExecAsync(context => {
21+
var dbSet = context.Set<DataItem>();
22+
23+
dbSet.AddRange(RemoteGroupCountTestHelper.GenerateTestData(() => new DataItem()));
24+
context.SaveChanges();
25+
26+
RemoteGroupCountTestHelper.Run(dbSet);
27+
});
28+
}
29+
30+
}
31+
32+
}
33+
#endif

net/DevExtreme.AspNet.Data.Tests.EFCore/TestDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) {
1616
modelBuilder.Entity<RemoteGrouping.DataItem>();
1717
#if !EFCORE1
1818
modelBuilder.Entity<RemoteGroupingStress.DataItem>();
19+
modelBuilder.Entity<RemoteGroupCount.DataItem>();
1920
#endif
2021
modelBuilder.Entity<Summary.DataItem>();
2122
modelBuilder.Entity<Bug120.DataItem>();

net/DevExtreme.AspNet.Data.Tests.L2S/DevExtreme.AspNet.Data.Tests.L2S.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
</ItemGroup>
8888
<ItemGroup>
8989
<Compile Include="AssemblyInfo.cs" />
90+
<Compile Include="RemoteGroupCount.cs" />
9091
<Compile Include="RemoteGroupingStress.cs" />
9192
<Compile Include="Summary.cs" />
9293
<Compile Include="T670222_TotalSummary.cs" />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Xunit;
4+
5+
namespace DevExtreme.AspNet.Data.Tests.L2S {
6+
using DataItem = RemoteGroupCount_DataItem;
7+
8+
public class RemoteGroupCount {
9+
10+
[Fact]
11+
public void Scenario() {
12+
TestDataContext.Exec(context => {
13+
var table = context.RemoteGroupCount_DataItems;
14+
15+
foreach(var i in RemoteGroupCountTestHelper.GenerateTestData(() => new DataItem()))
16+
table.InsertOnSubmit(i);
17+
context.SubmitChanges();
18+
19+
RemoteGroupCountTestHelper.Run(table);
20+
});
21+
}
22+
23+
}
24+
25+
}

net/DevExtreme.AspNet.Data.Tests.L2S/TestDataClasses.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public static void Exec(Action<TestDataContext> action) {
2323
)"
2424
);
2525

26+
INSTANCE.ExecuteCommand(
27+
$@"create table {nameof(RemoteGroupCount_DataItem)} (
28+
{nameof(RemoteGroupCount_DataItem.ID)} int identity primary key,
29+
{nameof(RemoteGroupCount_DataItem.G1)} int not null,
30+
{nameof(RemoteGroupCount_DataItem.G2)} int not null
31+
)"
32+
);
33+
2634
INSTANCE.ExecuteCommand(
2735
$@"create table {nameof(Summary_DataItem)} (
2836
{nameof(Summary_DataItem.ID)} int identity primary key,
@@ -51,6 +59,9 @@ public void PurgeGenericTestTable() {
5159
partial class RemoteGroupingStress_DataItem : RemoteGroupingStressHelper.IEntity {
5260
}
5361

62+
partial class RemoteGroupCount_DataItem : RemoteGroupCountTestHelper.IEntity {
63+
}
64+
5465
partial class Summary_DataItem : SummaryTestHelper.IEntity {
5566
}
5667

net/DevExtreme.AspNet.Data.Tests.L2S/TestDataClasses.dbml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
<Column Name="NullDate" Type="System.DateTime" DbType="datetime2" CanBeNull="true" />
99
</Type>
1010
</Table>
11+
<Table Name="" Member="RemoteGroupCount_DataItems">
12+
<Type Name="RemoteGroupCount_DataItem">
13+
<Column Name="ID" AutoSync="Never" Type="System.Int32" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
14+
<Column Name="G1" Type="System.Int32" CanBeNull="false" />
15+
<Column Name="G2" Type="System.Int32" CanBeNull="false" />
16+
</Type>
17+
</Table>
1118
<Table Name="" Member="Summary_DataItems">
1219
<Type Name="Summary_DataItem">
1320
<Column Name="ID" AutoSync="Never" Type="System.Int32" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />

0 commit comments

Comments
 (0)