From b5488f5d06a02942390fb9a16fcd8c2eb52608f0 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 5 Dec 2019 17:06:28 -0800 Subject: [PATCH 1/3] Query: Add regression test for #12337 --- .../Query/NorthwindSelectQueryCosmosTest.cs | 6 ++++ .../Query/NorthwindSelectQueryTestBase.cs | 22 +++++++++++++ .../NorthwindSelectQuerySqlServerTest.cs | 31 +++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs index 6e7c02f3a21..03c467dd4fb 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs @@ -1032,6 +1032,12 @@ public override Task LastOrDefault_member_access_in_projection_translates_to_ser return base.LastOrDefault_member_access_in_projection_translates_to_server(async); } + [ConditionalTheory(Skip = "Issue#17246")] + public override Task Collection_projection_AsNoTracking_OrderBy(bool async) + { + return base.Collection_projection_AsNoTracking_OrderBy(async); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs index 57637167269..bfdd0b35b81 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs @@ -1593,5 +1593,27 @@ public CustomerWrapper(Customer customer) public string City { get; set; } public Customer Customer { get; } } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Collection_projection_AsNoTracking_OrderBy(bool async) + { + return AssertQuery( + async, + ss => (from c in ss.Set() + select new + { + c.CustomerID, + Orders = c.Orders.Select(o => o.OrderDate).ToList() + }) + .AsNoTracking() + .OrderBy(a => a.CustomerID), + assertOrder: true, + elementAsserter: (e, a) => + { + Assert.Equal(e.CustomerID, a.CustomerID); + AssertCollection(e.Orders, a.Orders, elementSorter: i => i, elementAsserter: (ie, ia) => Assert.Equal(ie, ia)); + }); + } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs index 4ca761331dd..7066575f684 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs @@ -1271,6 +1271,37 @@ FROM [Customers] AS [c] WHERE [c].[CustomerID] LIKE N'A%'"); } + public override async Task Projection_with_parameterized_constructor(bool async) + { + await base.Projection_with_parameterized_constructor(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] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI'"); + } + + public override async Task Projection_with_parameterized_constructor_with_member_assignment(bool async) + { + await base.Projection_with_parameterized_constructor_with_member_assignment(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] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI'"); + } + + public override async Task Collection_projection_AsNoTracking_OrderBy(bool async) + { + await base.Collection_projection_AsNoTracking_OrderBy(async); + + AssertSql( + @"SELECT [c].[CustomerID], [o].[OrderDate], [o].[OrderID] +FROM [Customers] AS [c] +LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +ORDER BY [c].[CustomerID], [o].[OrderID]"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); From 0bc78b9b346c3e43a0d4e94e17be122b97af633d Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 5 Dec 2019 17:40:40 -0800 Subject: [PATCH 2/3] Query: Add regression test for #12355 --- .../NorthwindGroupByQueryInMemoryTest.cs | 8 +++++ .../Query/NorthwindGroupByQueryTestBase.cs | 36 +++++++++++++++++++ .../NorthwindGroupByQuerySqlServerTest.cs | 16 +++++++++ 3 files changed, 60 insertions(+) diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindGroupByQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindGroupByQueryInMemoryTest.cs index bb5a7838c0c..af3d6fd6bce 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindGroupByQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindGroupByQueryInMemoryTest.cs @@ -1,7 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query @@ -16,5 +18,11 @@ public NorthwindGroupByQueryInMemoryTest( { //TestLoggerFactory.TestOutputHelper = testOutputHelper; } + + [ConditionalTheory(Skip = "Issue#17536")] + public override Task Join_GroupBy_Aggregate_with_left_join(bool async) + { + return base.Join_GroupBy_Aggregate_with_left_join(async); + } } } diff --git a/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs index 7b058120292..71e245868c9 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs @@ -1745,6 +1745,42 @@ from g in grouping entryCount: 63); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Join_GroupBy_Aggregate_with_left_join(bool async) + { + return AssertQuery( + async, + ss => + from c in ss.Set().Where(c => c.CustomerID.StartsWith("A")) + join a in ss.Set().GroupBy(o => o.CustomerID) + .Where(g => g.Count() > 5) + .Select( + g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) }) + on c.CustomerID equals a.CustomerID into grouping + from g in grouping.DefaultIfEmpty() + select new + { + c, + LastOrderID = (int?)g.LastOrderID + }, + ss => + from c in ss.Set().Where(c => c.CustomerID.StartsWith("A")) + join a in ss.Set().GroupBy(o => o.CustomerID) + .Where(g => g.Count() > 5) + .Select( + g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) }) + on c.CustomerID equals a.CustomerID into grouping + from g in grouping.DefaultIfEmpty() + select new + { + c, + LastOrderID = g != null ? g.LastOrderID : (int?)null + }, + elementSorter: r => r.c.CustomerID, + entryCount: 4); + } + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_GroupBy_Aggregate_in_subquery(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs index 195653a129f..7114bb61aa8 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs @@ -1334,6 +1334,22 @@ HAVING COUNT(*) > 5 INNER JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID]"); } + public override async Task Join_GroupBy_Aggregate_with_left_join(bool async) + { + await base.Join_GroupBy_Aggregate_with_left_join(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 [LastOrderID] +FROM [Customers] AS [c] +LEFT JOIN ( + SELECT [o].[CustomerID], MAX([o].[OrderID]) AS [c] + FROM [Orders] AS [o] + GROUP BY [o].[CustomerID] + HAVING COUNT(*) > 5 +) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +WHERE [c].[CustomerID] LIKE N'A%'"); + } + public override async Task Join_GroupBy_Aggregate_in_subquery(bool async) { await base.Join_GroupBy_Aggregate_in_subquery(async); From 47d225a21e00ceb0acfd70e5ddaf77b1e1d84d06 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 5 Dec 2019 17:46:10 -0800 Subject: [PATCH 3/3] Query: Add regression test for #12437 --- .../NorthwindMiscellaneousQueryCosmosTest.cs | 6 ++++++ .../NorthwindMiscellaneousQueryTestBase.cs | 13 ++++++++++++ ...orthwindMiscellaneousQuerySqlServerTest.cs | 20 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs index 61a40efc37a..9e77b740c3b 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs @@ -3976,6 +3976,12 @@ public override Task SelectMany_correlated_subquery_hard(bool async) return base.SelectMany_correlated_subquery_hard(async); } + [ConditionalTheory(Skip = "Issue #17246")] + public override Task Subquery_DefaultIfEmpty_Any(bool async) + { + return base.Subquery_DefaultIfEmpty_Any(async); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs index 8ab58b4a743..45a544a2ac0 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs @@ -5463,5 +5463,18 @@ public virtual Task AsQueryable_in_query_server_evals(bool async) } private static Expression> ValidYear => a => a.OrderDate.Value.Year == 1998; + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Subquery_DefaultIfEmpty_Any(bool async) + { + return AssertAny( + async, + ss => (from e in ss.Set() + .Where(e => e.EmployeeID == NonExistentID) + .Select(e => e.EmployeeID) + .DefaultIfEmpty() + select e)); + } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs index e7047d92c54..6d84f6276b4 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs @@ -4691,6 +4691,26 @@ ORDER BY [o].[OrderID] ORDER BY [c].[CustomerID], [t].[OrderID]"); } + public override async Task Subquery_DefaultIfEmpty_Any(bool async) + { + await base.Subquery_DefaultIfEmpty_Any(async); + + AssertSql( + @"SELECT CASE + WHEN EXISTS ( + SELECT 1 + FROM ( + SELECT NULL AS [empty] + ) AS [empty] + LEFT JOIN ( + SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] + FROM [Employees] AS [e] + WHERE [e].[EmployeeID] = -1 + ) AS [t] ON 1 = 1) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected);