Skip to content

Commit

Permalink
Query: Add TPT variant for FilterInheritanceQueryTests
Browse files Browse the repository at this point in the history
Part of #21510
  • Loading branch information
smitpatel committed Jul 7, 2020
1 parent da5ed2e commit f785389
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<TFixture> : FiltersInheritanceQueryTestBase<TFixture>
where TFixture : TPTInheritanceQueryFixture, new()
{
public TPTFiltersInheritanceQueryTestBase(TFixture fixture)
: base(fixture)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<TPTFiltersInheritanceQuerySqlServerFixture>
{
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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<TPTFiltersInheritanceQuerySqliteFixture>
{
public TPTFiltersInheritanceQuerySqliteTest(TPTFiltersInheritanceQuerySqliteFixture fixture)
: base(fixture)
{
}
}
}

0 comments on commit f785389

Please sign in to comment.