From 98dab8df770ca54803df5fd4286107c89da26bda Mon Sep 17 00:00:00 2001 From: maumar Date: Wed, 24 Apr 2024 13:43:51 -0700 Subject: [PATCH] Fix to #33590 - Test ordering issue Moving the problematic tests from base to SQL Server, where they happen to return results in default order, rather than removing the tests altogether. Fixes #33590 --- .../MaterializationInterceptionCosmosTest.cs | 8 - .../Query/ComplexNavigationsQueryTestBase.cs | 20 -- .../ComplexNavigationsQuerySqlServerTest.cs | 97 +++++----- ...NavigationsSharedTypeQuerySqlServerTest.cs | 173 ++++++++++-------- 4 files changed, 150 insertions(+), 148 deletions(-) diff --git a/test/EFCore.Cosmos.FunctionalTests/MaterializationInterceptionCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/MaterializationInterceptionCosmosTest.cs index 61fd9aea95e..b58c881d792 100644 --- a/test/EFCore.Cosmos.FunctionalTests/MaterializationInterceptionCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/MaterializationInterceptionCosmosTest.cs @@ -36,14 +36,6 @@ public override Task Multiple_materialization_interceptors_can_be_used(bool inje public override Task Intercept_query_materialization_for_empty_constructor(bool inject, bool usePooling) => base.Intercept_query_materialization_for_empty_constructor(inject, usePooling); - - - - - - - - protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance; } diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs index 5a23a69a79f..8cc5fee20d5 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs @@ -3381,26 +3381,6 @@ public virtual Task Member_over_null_check_ternary_and_nested_anonymous_type(boo } }); - [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Distinct_skip_without_orderby(bool async) - => AssertQuery( - async, - ss => from l1 in ss.Set() - where l1.Id < 3 - select (from l3 in ss.Set() - select l3).Distinct().Skip(1).OrderBy(e => e.Id).FirstOrDefault().Name); - - [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Distinct_take_without_orderby(bool async) - => AssertQuery( - async, - ss => from l1 in ss.Set() - where l1.Id < 3 - select (from l3 in ss.Set() - select l3).Distinct().Take(1).OrderBy(e => e.Id).FirstOrDefault().Name); - [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Let_let_contains_from_outer_let(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs index b9612240271..762d51aa38a 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; using Xunit.Sdk; namespace Microsoft.EntityFrameworkCore.Query; @@ -22,6 +23,61 @@ public class ComplexNavigationsQuerySqlServerTest : ComplexNavigationsQueryRelat public virtual void Check_all_tests_overridden() => TestHelpers.AssertAllMethodsOverridden(GetType()); + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Distinct_skip_without_orderby(bool async) + { + await AssertQuery( + async, + ss => from l1 in ss.Set() + where l1.Id < 3 + select (from l3 in ss.Set() + select l3).Distinct().Skip(1).OrderBy(e => e.Id).FirstOrDefault().Name); + + AssertSql( +""" +SELECT ( + SELECT TOP(1) [l2].[Name] + FROM ( + SELECT [l1].[Id], [l1].[Name] + FROM ( + SELECT DISTINCT [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] + FROM [LevelThree] AS [l0] + ) AS [l1] + ORDER BY (SELECT 1) + OFFSET 1 ROWS + ) AS [l2] + ORDER BY [l2].[Id]) +FROM [LevelOne] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Distinct_take_without_orderby(bool async) + { + await AssertQuery( + async, + ss => from l1 in ss.Set() + where l1.Id < 3 + select (from l3 in ss.Set() + select l3).Distinct().Take(1).OrderBy(e => e.Id).FirstOrDefault().Name); + + AssertSql( +""" +SELECT ( + SELECT TOP(1) [l1].[Name] + FROM ( + SELECT DISTINCT TOP(1) [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] + FROM [LevelThree] AS [l0] + ) AS [l1] + ORDER BY [l1].[Id]) +FROM [LevelOne] AS [l] +WHERE [l].[Id] < 3 +"""); + } + public override async Task Entity_equality_empty(bool async) { await base.Entity_equality_empty(async); @@ -3998,47 +4054,6 @@ WHERE CASE """); } - public override async Task Distinct_skip_without_orderby(bool async) - { - await base.Distinct_skip_without_orderby(async); - - AssertSql( - """ -SELECT ( - SELECT TOP(1) [l2].[Name] - FROM ( - SELECT [l1].[Id], [l1].[Name] - FROM ( - SELECT DISTINCT [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] - FROM [LevelThree] AS [l0] - ) AS [l1] - ORDER BY (SELECT 1) - OFFSET 1 ROWS - ) AS [l2] - ORDER BY [l2].[Id]) -FROM [LevelOne] AS [l] -WHERE [l].[Id] < 3 -"""); - } - - public override async Task Distinct_take_without_orderby(bool async) - { - await base.Distinct_take_without_orderby(async); - - AssertSql( - """ -SELECT ( - SELECT TOP(1) [l1].[Name] - FROM ( - SELECT DISTINCT TOP(1) [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] - FROM [LevelThree] AS [l0] - ) AS [l1] - ORDER BY [l1].[Id]) -FROM [LevelOne] AS [l] -WHERE [l].[Id] < 3 -"""); - } - public override async Task Let_let_contains_from_outer_let(bool async) { await base.Let_let_contains_from_outer_let(async); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs index d7a5ad1b4ab..e686a5035b7 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; using Xunit.Sdk; namespace Microsoft.EntityFrameworkCore.Query; @@ -23,6 +24,99 @@ public class ComplexNavigationsSharedTypeQuerySqlServerTest : public virtual void Check_all_tests_overridden() => TestHelpers.AssertAllMethodsOverridden(GetType()); + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Distinct_skip_without_orderby(bool async) + { + await AssertQuery( + async, + ss => from l1 in ss.Set() + where l1.Id < 3 + select (from l3 in ss.Set() + select l3).Distinct().Skip(1).OrderBy(e => e.Id).FirstOrDefault().Name); + + AssertSql( +""" +SELECT ( + SELECT TOP(1) [s0].[Level3_Name] + FROM ( + SELECT [s].[Id], [s].[Level2_Required_Id], [s].[Level3_Name], [s].[OneToMany_Required_Inverse3Id] + FROM ( + SELECT DISTINCT [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + WHERE [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [l2] ON [l0].[Id] = CASE + WHEN [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l4] ON CASE + WHEN [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] + END = CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END + WHERE [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL AND [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [s] + ORDER BY (SELECT 1) + OFFSET 1 ROWS + ) AS [s0] + ORDER BY CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id] + END) +FROM [Level1] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Distinct_take_without_orderby(bool async) + { + await AssertQuery( + async, + ss => from l1 in ss.Set() + where l1.Id < 3 + select (from l3 in ss.Set() + select l3).Distinct().Take(1).OrderBy(e => e.Id).FirstOrDefault().Name); + + AssertSql( +""" +SELECT ( + SELECT TOP(1) [s].[Level3_Name] + FROM ( + SELECT DISTINCT TOP(1) [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + WHERE [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [l2] ON [l0].[Id] = CASE + WHEN [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l4] ON CASE + WHEN [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] + END = CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END + WHERE [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL AND [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [s] + ORDER BY CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id] + END) +FROM [Level1] AS [l] +WHERE [l].[Id] < 3 +"""); + } + public override async Task Simple_level1_include(bool async) { await base.Simple_level1_include(async); @@ -506,43 +600,6 @@ public override async Task Sum_with_filter_with_include_selector_cast_using_as(b """); } - public override async Task Distinct_take_without_orderby(bool async) - { - await base.Distinct_take_without_orderby(async); - - AssertSql( - """ -SELECT ( - SELECT TOP(1) [s].[Level3_Name] - FROM ( - SELECT DISTINCT TOP(1) [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id] - FROM [Level1] AS [l0] - LEFT JOIN ( - SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] - FROM [Level1] AS [l1] - WHERE [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL - ) AS [l2] ON [l0].[Id] = CASE - WHEN [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] - END - LEFT JOIN ( - SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id] - FROM [Level1] AS [l3] - WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL - ) AS [l4] ON CASE - WHEN [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] - END = CASE - WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] - END - WHERE [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL AND [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL - ) AS [s] - ORDER BY CASE - WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id] - END) -FROM [Level1] AS [l] -WHERE [l].[Id] < 3 -"""); - } - public override async Task Let_let_contains_from_outer_let(bool async) { await base.Let_let_contains_from_outer_let(async); @@ -1016,48 +1073,6 @@ UNION ALL """); } - public override async Task Distinct_skip_without_orderby(bool async) - { - await base.Distinct_skip_without_orderby(async); - - AssertSql( - """ -SELECT ( - SELECT TOP(1) [s0].[Level3_Name] - FROM ( - SELECT [s].[Id], [s].[Level2_Required_Id], [s].[Level3_Name], [s].[OneToMany_Required_Inverse3Id] - FROM ( - SELECT DISTINCT [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id] - FROM [Level1] AS [l0] - LEFT JOIN ( - SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] - FROM [Level1] AS [l1] - WHERE [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL - ) AS [l2] ON [l0].[Id] = CASE - WHEN [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] - END - LEFT JOIN ( - SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id] - FROM [Level1] AS [l3] - WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL - ) AS [l4] ON CASE - WHEN [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] - END = CASE - WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] - END - WHERE [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL AND [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL - ) AS [s] - ORDER BY (SELECT 1) - OFFSET 1 ROWS - ) AS [s0] - ORDER BY CASE - WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id] - END) -FROM [Level1] AS [l] -WHERE [l].[Id] < 3 -"""); - } - [ConditionalTheory(Skip = "Issue #26104")] public override async Task GroupBy_aggregate_where_required_relationship(bool async) {