Skip to content

Commit

Permalink
Add regression tests for issue#10012 (#21589)
Browse files Browse the repository at this point in the history
Resolves #10012
  • Loading branch information
smitpatel committed Jul 11, 2020
1 parent 0a0a455 commit 58abc39
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
Expand Up @@ -2205,6 +2205,61 @@ public virtual Task GroupBy_aggregate_over_a_subquery(bool async)
}));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_aggregate_join_with_grouping_key(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>()
.GroupBy(o => o.CustomerID)
.Select(g => new { g.Key, Count = g.Count() })
.Join(ss.Set<Customer>(), o => o.Key, c => c.CustomerID, (o, c) => new { c, o.Count }),
elementSorter: a => a.c.CustomerID,
elementAsserter: (e, a) =>
{
AssertEqual(e.c, a.c);
AssertEqual(e.Count, a.Count);
},
entryCount: 89);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_aggregate_join_with_group_result(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>()
.GroupBy(o => o.CustomerID, e => e.OrderDate)
.Select(g => new { g.Key, LastOrderDate = g.Max() })
.Join(ss.Set<Order>(), o => o, i => new { Key = i.CustomerID, LastOrderDate = i.OrderDate }, (_, x) => x),
entryCount: 90);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_aggregate_from_right_side_of_join(bool async)
{
return AssertQuery(
async,
ss => (from c in ss.Set<Customer>()
join o in ss.Set<Order>().GroupBy(i => i.CustomerID).Select(e => new { e.Key, Max = e.Max(i => i.OrderDate) })
on c.CustomerID equals o.Key
select new { c, o.Max })
.OrderBy(e => e.Max)
.ThenBy(c => c.c.CustomerID)
.Skip(10)
.Take(10),
assertOrder: true,
elementAsserter: (e, a) =>
{
AssertEqual(e.c, a.c);
AssertEqual(e.Max, a.Max);
},
entryCount: 10);
}

#endregion

#region GroupByWithoutAggregate
Expand Down
Expand Up @@ -1930,6 +1930,52 @@ SELECT COUNT(*)
GROUP BY [o].[CustomerID]");
}

public override async Task GroupBy_aggregate_join_with_grouping_key(bool async)
{
await base.GroupBy_aggregate_join_with_grouping_key(async);

AssertSql(
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [t].[c] AS [Count]
FROM (
SELECT [o].[CustomerID], COUNT(*) AS [c]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]
) AS [t]
INNER JOIN [Customers] AS [c] ON [t].[CustomerID] = [c].[CustomerID]");
}

public override async Task GroupBy_aggregate_join_with_group_result(bool async)
{
await base.GroupBy_aggregate_join_with_group_result(async);

AssertSql(
@"SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
FROM (
SELECT [o].[CustomerID], MAX([o].[OrderDate]) AS [c]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]
) AS [t]
INNER JOIN [Orders] AS [o0] ON (([t].[CustomerID] = [o0].[CustomerID]) OR ([t].[CustomerID] IS NULL AND [o0].[CustomerID] IS NULL)) AND (([t].[c] = [o0].[OrderDate]) OR ([t].[c] IS NULL AND [o0].[OrderDate] IS NULL))");
}

public override async Task GroupBy_aggregate_from_right_side_of_join(bool async)
{
await base.GroupBy_aggregate_from_right_side_of_join(async);

AssertSql(
@"@__p_0='10'
SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [t].[c] AS [Max]
FROM [Customers] AS [c]
INNER JOIN (
SELECT [o].[CustomerID], MAX([o].[OrderDate]) AS [c]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]
) AS [t] ON [c].[CustomerID] = [t].[CustomerID]
ORDER BY [t].[c], [c].[CustomerID]
OFFSET @__p_0 ROWS FETCH NEXT @__p_0 ROWS ONLY");
}

public override async Task GroupBy_with_grouping_key_using_Like(bool async)
{
await base.GroupBy_with_grouping_key_using_Like(async);
Expand Down

0 comments on commit 58abc39

Please sign in to comment.