From 99de4a66633525af356f4a0f55a55301ccb4bf82 Mon Sep 17 00:00:00 2001 From: Maurycy Markowski Date: Thu, 16 Sep 2021 16:07:55 -0700 Subject: [PATCH] Adding regression test for #15279 We already have regression tests for most of the scenarios mentioned in the issue report. Adding the one scenario that was missing. Resolves #15279 --- .../Query/NorthwindGroupByQueryTestBase.cs | 25 +++++++++++++++++ .../NorthwindGroupByQuerySqlServerTest.cs | 27 +++++++++++++++++++ .../Query/NorthwindGroupByQuerySqliteTest.cs | 6 +++++ 3 files changed, 58 insertions(+) diff --git a/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs index 1618e573add..6f89bffc442 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs @@ -3300,6 +3300,31 @@ public virtual Task Complex_query_with_groupBy_in_subquery4(bool async) }); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Complex_query_with_group_by_in_subquery5(bool async) + { + return AssertQuery( + async, + ss => from od in ss.Set() + where od.Order.Customer.CustomerID == "ALFKI" + group od by od.ProductID into grouping + select new + { + Sum = grouping.Sum(x => x.ProductID + x.OrderID * 1000), + Subquery = (from c in ss.Set() + where c.CustomerID.Length < grouping.Min(x => x.OrderID / 100) + orderby c.CustomerID + select new { c.CustomerID, c.City }).ToList() + }, + elementSorter: e => e.Sum, + elementAsserter: (e, a) => + { + AssertEqual(e.Sum, a.Sum); + AssertCollection(e.Subquery, a.Subquery, elementSorter: ee => ee.CustomerID); + }); + } + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_scalar_subquery(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs index 3e5f589eb62..6cf9201655c 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs @@ -2847,6 +2847,33 @@ public override async Task Select_correlated_collection_after_GroupBy_aggregate_ //AssertSql(" "); } + public override async Task Complex_query_with_group_by_in_subquery5(bool async) + { + await base.Complex_query_with_group_by_in_subquery5(async); + + AssertSql( + @"SELECT [t].[c], [t].[ProductID], [t0].[CustomerID], [t0].[City] +FROM ( + SELECT COALESCE(SUM([o].[ProductID] + ([o].[OrderID] * 1000)), 0) AS [c], [o].[ProductID] + FROM [Order Details] AS [o] + INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] + LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] + WHERE [c].[CustomerID] = N'ALFKI' + GROUP BY [o].[ProductID] +) AS [t] +OUTER APPLY ( + SELECT [c0].[CustomerID], [c0].[City] + FROM [Customers] AS [c0] + WHERE CAST(LEN([c0].[CustomerID]) AS int) < ( + SELECT MIN([o1].[OrderID] / 100) + FROM [Order Details] AS [o1] + INNER JOIN [Orders] AS [o2] ON [o1].[OrderID] = [o2].[OrderID] + LEFT JOIN [Customers] AS [c1] ON [o2].[CustomerID] = [c1].[CustomerID] + WHERE ([c1].[CustomerID] = N'ALFKI') AND ([t].[ProductID] = [o1].[ProductID])) +) AS [t0] +ORDER BY [t].[ProductID], [t0].[CustomerID]"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindGroupByQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindGroupByQuerySqliteTest.cs index 2ddf4a1dc46..6039d0f7ca4 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindGroupByQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindGroupByQuerySqliteTest.cs @@ -68,6 +68,12 @@ public override async Task Select_nested_collection_with_groupby(bool async) (await Assert.ThrowsAsync( () => base.Select_nested_collection_with_groupby(async))).Message); + public override async Task Complex_query_with_group_by_in_subquery5(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Complex_query_with_group_by_in_subquery5(async))).Message); + public override async Task Odata_groupby_empty_key(bool async) => await Assert.ThrowsAsync(() => base.Odata_groupby_empty_key(async)); }