diff --git a/test/EFCore.Relational.Specification.Tests/Query/TPTFiltersInheritanceQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/TPTFiltersInheritanceQueryTestBase.cs new file mode 100644 index 00000000000..0c87d1a3a26 --- /dev/null +++ b/test/EFCore.Relational.Specification.Tests/Query/TPTFiltersInheritanceQueryTestBase.cs @@ -0,0 +1,17 @@ +// 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. + + +// ReSharper disable InconsistentNaming + +namespace Microsoft.EntityFrameworkCore.Query +{ + public abstract class TPTFiltersInheritanceQueryTestBase : FiltersInheritanceQueryTestBase + where TFixture : TPTInheritanceQueryFixture, new() + { + public TPTFiltersInheritanceQueryTestBase(TFixture fixture) + : base(fixture) + { + } + } +} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTFiltersInheritanceQuerySqlServerFixture.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTFiltersInheritanceQuerySqlServerFixture.cs new file mode 100644 index 00000000000..3c3fe1dd833 --- /dev/null +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTFiltersInheritanceQuerySqlServerFixture.cs @@ -0,0 +1,10 @@ +// 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. + +namespace Microsoft.EntityFrameworkCore.Query +{ + public class TPTFiltersInheritanceQuerySqlServerFixture : TPTInheritanceQuerySqlServerFixture + { + protected override bool EnableFilters => true; + } +} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTFiltersInheritanceQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTFiltersInheritanceQuerySqlServerTest.cs new file mode 100644 index 00000000000..e5bb9b4d011 --- /dev/null +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTFiltersInheritanceQuerySqlServerTest.cs @@ -0,0 +1,180 @@ +// 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 Xunit.Abstractions; + +namespace Microsoft.EntityFrameworkCore.Query +{ + public class TPTFiltersInheritanceQuerySqlServerTest : TPTFiltersInheritanceQueryTestBase + { + public TPTFiltersInheritanceQuerySqlServerTest(TPTFiltersInheritanceQuerySqlServerFixture fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + public override void Can_use_of_type_animal() + { + base.Can_use_of_type_animal(); + + AssertSql( + @"SELECT [a].[Species], [a].[CountryId], [a].[Name], [b].[EagleId], [b].[IsFlightless], [e].[Group], [k].[FoundOn], CASE + WHEN [e].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsEagle], CASE + WHEN [k].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsKiwi] +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE [a].[CountryId] = 1 +ORDER BY [a].[Species]"); + } + + public override void Can_use_is_kiwi() + { + base.Can_use_is_kiwi(); + + AssertSql( + @"SELECT [a].[Species], [a].[CountryId], [a].[Name], [b].[EagleId], [b].[IsFlightless], [e].[Group], [k].[FoundOn], CASE + WHEN [e].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsEagle], CASE + WHEN [k].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsKiwi] +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE ([a].[CountryId] = 1) AND [k].[Species] IS NOT NULL"); + } + + public override void Can_use_is_kiwi_with_other_predicate() + { + base.Can_use_is_kiwi_with_other_predicate(); + + AssertSql( + @"SELECT [a].[Species], [a].[CountryId], [a].[Name], [b].[EagleId], [b].[IsFlightless], [e].[Group], [k].[FoundOn], CASE + WHEN [e].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsEagle], CASE + WHEN [k].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsKiwi] +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE ([a].[CountryId] = 1) AND ([k].[Species] IS NOT NULL AND ([a].[CountryId] = 1))"); + } + + public override void Can_use_is_kiwi_in_projection() + { + base.Can_use_is_kiwi_in_projection(); + + AssertSql( + @"SELECT CASE + WHEN [k].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE [a].[CountryId] = 1"); + } + + public override void Can_use_of_type_bird() + { + base.Can_use_of_type_bird(); + + AssertSql( + @"SELECT [a].[Species], [a].[CountryId], [a].[Name], [b].[EagleId], [b].[IsFlightless], [e].[Group], [k].[FoundOn], CASE + WHEN [e].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsEagle], CASE + WHEN [k].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsKiwi] +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE ([a].[CountryId] = 1) AND ([e].[Species] IS NOT NULL OR [k].[Species] IS NOT NULL) +ORDER BY [a].[Species]"); + } + + public override void Can_use_of_type_bird_predicate() + { + base.Can_use_of_type_bird_predicate(); + + AssertSql( + @"SELECT [a].[Species], [a].[CountryId], [a].[Name], [b].[EagleId], [b].[IsFlightless], [e].[Group], [k].[FoundOn], CASE + WHEN [e].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsEagle], CASE + WHEN [k].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsKiwi] +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE (([a].[CountryId] = 1) AND ([a].[CountryId] = 1)) AND ([e].[Species] IS NOT NULL OR [k].[Species] IS NOT NULL) +ORDER BY [a].[Species]"); + } + + public override void Can_use_of_type_bird_with_projection() + { + base.Can_use_of_type_bird_with_projection(); + + AssertSql( + @"SELECT [b].[EagleId] +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE ([a].[CountryId] = 1) AND ([e].[Species] IS NOT NULL OR [k].[Species] IS NOT NULL)"); + } + + public override void Can_use_of_type_bird_first() + { + base.Can_use_of_type_bird_first(); + + AssertSql( + @"SELECT TOP(1) [a].[Species], [a].[CountryId], [a].[Name], [b].[EagleId], [b].[IsFlightless], [e].[Group], [k].[FoundOn], CASE + WHEN [e].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsEagle], CASE + WHEN [k].[Species] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsKiwi] +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE ([a].[CountryId] = 1) AND ([e].[Species] IS NOT NULL OR [k].[Species] IS NOT NULL) +ORDER BY [a].[Species]"); + } + + public override void Can_use_of_type_kiwi() + { + base.Can_use_of_type_kiwi(); + + AssertSql( + @"SELECT [a].[Species], [a].[CountryId], [a].[Name], [b].[EagleId], [b].[IsFlightless], [k].[FoundOn] +FROM [Animals] AS [a] +LEFT JOIN [Birds] AS [b] ON [a].[Species] = [b].[Species] +LEFT JOIN [Eagle] AS [e] ON [a].[Species] = [e].[Species] +LEFT JOIN [Kiwi] AS [k] ON [a].[Species] = [k].[Species] +WHERE ([a].[CountryId] = 1) AND [k].[Species] IS NOT NULL"); + } + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + } +} diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/TPTFiltersInheritanceQuerySqliteFixture.cs b/test/EFCore.Sqlite.FunctionalTests/Query/TPTFiltersInheritanceQuerySqliteFixture.cs new file mode 100644 index 00000000000..b6bc031f8ab --- /dev/null +++ b/test/EFCore.Sqlite.FunctionalTests/Query/TPTFiltersInheritanceQuerySqliteFixture.cs @@ -0,0 +1,10 @@ +// 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. + +namespace Microsoft.EntityFrameworkCore.Query +{ + public class TPTFiltersInheritanceQuerySqliteFixture : TPTInheritanceQuerySqliteFixture + { + protected override bool EnableFilters => true; + } +} diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/TPTFiltersInheritanceQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/TPTFiltersInheritanceQuerySqliteTest.cs new file mode 100644 index 00000000000..6b9a8a599e5 --- /dev/null +++ b/test/EFCore.Sqlite.FunctionalTests/Query/TPTFiltersInheritanceQuerySqliteTest.cs @@ -0,0 +1,13 @@ +// 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. + +namespace Microsoft.EntityFrameworkCore.Query +{ + public class TPTFiltersInheritanceQuerySqliteTest : TPTFiltersInheritanceQueryTestBase + { + public TPTFiltersInheritanceQuerySqliteTest(TPTFiltersInheritanceQuerySqliteFixture fixture) + : base(fixture) + { + } + } +}