Skip to content

Commit

Permalink
Query: Add TPT variant for GearsOfWarQueryTests (#21532)
Browse files Browse the repository at this point in the history
Part of #21510
  • Loading branch information
smitpatel authored Jul 7, 2020
1 parent 39e8b17 commit 230ac18
Show file tree
Hide file tree
Showing 9 changed files with 9,140 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore.Query
{
public abstract class TPTGearsOfWarQueryRelationalFixture : GearsOfWarQueryFixtureBase
{
protected override string StoreName { get; } = "TPTGearsOfWarQueryTest";
public new RelationalTestStore TestStore => (RelationalTestStore)base.TestStore;

public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory;

protected override bool ShouldLogCategory(string logCategory)
=> logCategory == DbLoggerCategory.Query.Name;

protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
{
base.OnModelCreating(modelBuilder, context);

modelBuilder.Entity<Gear>().ToTable("Gears");
modelBuilder.Entity<Officer>().ToTable("Officers");

modelBuilder.Entity<Faction>().ToTable("Factions");
modelBuilder.Entity<LocustHorde>().ToTable("LocustHordes");

modelBuilder.Entity<LocustLeader>().ToTable("LocustLeaders");
modelBuilder.Entity<LocustCommander>().ToTable("LocustCommanders");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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 abstract class TPTGearsOfWarQueryRelationalTestBase<TFixture> : GearsOfWarQueryRelationalTestBase<TFixture>
where TFixture : TPTGearsOfWarQueryRelationalFixture, new()
{
protected TPTGearsOfWarQueryRelationalTestBase(TFixture fixture)
: base(fixture)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void AssertBaseline(string[] expected)
Logger.TestOutputHelper?.WriteLine("---- New Baseline -------------------------------------------------------------------");
Logger.TestOutputHelper?.WriteLine(newBaseLine);

var contents = testInfo + newBaseLine + FileNewLine + FileNewLine;
var contents = testInfo + newBaseLine + FileNewLine + "--------------------" + FileNewLine;

File.AppendAllText(logFile, contents);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore.Query
{
public class TPTGearsOfWarQuerySqlServerFixture : TPTGearsOfWarQueryRelationalFixture
{
protected override ITestStoreFactory TestStoreFactory => SqlServerTestStoreFactory.Instance;

protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
{
base.OnModelCreating(modelBuilder, context);

modelBuilder.Entity<City>().Property(g => g.Location).HasColumnType("varchar(100)");
}
}
}
8,840 changes: 8,840 additions & 0 deletions test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,28 @@ public override async Task Byte_array_filter_by_SequenceEqual(bool async)
WHERE ""s"".""Banner5"" = @__byteArrayParam_0");
}

[ConditionalTheory(Skip = "PR #19774")]
[ConditionalTheory(Skip = "Issue#18844")]
public override Task TimeSpan_Hours(bool async) => base.TimeSpan_Hours(async);

[ConditionalTheory(Skip = "PR #19774")]
[ConditionalTheory(Skip = "Issue#18844")]
public override Task TimeSpan_Minutes(bool async) => base.TimeSpan_Minutes(async);

[ConditionalTheory(Skip = "PR #19774")]
[ConditionalTheory(Skip = "Issue#18844")]
public override Task TimeSpan_Seconds(bool async) => base.TimeSpan_Seconds(async);

[ConditionalTheory(Skip = "PR #19774")]
[ConditionalTheory(Skip = "Issue#18844")]
public override Task TimeSpan_Milliseconds(bool async) => base.TimeSpan_Milliseconds(async);

[ConditionalTheory(Skip = "PR #19774")]
[ConditionalTheory(Skip = "Issue#18844")]
public override Task Where_TimeSpan_Hours(bool async) => base.Where_TimeSpan_Hours(async);

[ConditionalTheory(Skip = "PR #19774")]
[ConditionalTheory(Skip = "Issue#18844")]
public override Task Where_TimeSpan_Minutes(bool async) => base.Where_TimeSpan_Minutes(async);

[ConditionalTheory(Skip = "PR #19774")]
[ConditionalTheory(Skip = "Issue#18844")]
public override Task Where_TimeSpan_Seconds(bool async) => base.Where_TimeSpan_Seconds(async);

[ConditionalTheory(Skip = "PR #19774")]
[ConditionalTheory(Skip = "Issue#18844")]
public override Task Where_TimeSpan_Milliseconds(bool async) => base.Where_TimeSpan_Milliseconds(async);

private void AssertSql(params string[] expected)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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 Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore.Query
{
public class TPTGearsOfWarQuerySqliteFixture : TPTGearsOfWarQueryRelationalFixture
{
protected override ITestStoreFactory TestStoreFactory => SqliteTestStoreFactory.Instance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
// 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 Xunit;
using Xunit.Abstractions;

namespace Microsoft.EntityFrameworkCore.Query
{
public class TPTGearsOfWarQuerySqliteTest : TPTGearsOfWarQueryRelationalTestBase<TPTGearsOfWarQuerySqliteFixture>
{
public TPTGearsOfWarQuerySqliteTest(TPTGearsOfWarQuerySqliteFixture fixture, ITestOutputHelper testOutputHelper)
: base(fixture)
{
Fixture.TestSqlLoggerFactory.Clear();
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

public override Task Where_datetimeoffset_date_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_date_component(async));

public override Task Where_datetimeoffset_day_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_date_component(async));

public override Task Where_datetimeoffset_dayofyear_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_dayofyear_component(async));

public override Task Where_datetimeoffset_hour_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_hour_component(async));

public override Task Where_datetimeoffset_millisecond_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_millisecond_component(async));

public override Task Where_datetimeoffset_minute_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_minute_component(async));

public override Task Where_datetimeoffset_month_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_month_component(async));

public override Task Where_datetimeoffset_now(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_now(async));

public override Task Where_datetimeoffset_second_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_second_component(async));

public override Task Where_datetimeoffset_utcnow(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_utcnow(async));

public override Task Where_datetimeoffset_year_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_year_component(async));

public override Task DateTimeOffset_Contains_Less_than_Greater_than(bool async)
=> AssertTranslationFailed(() => base.DateTimeOffset_Contains_Less_than_Greater_than(async));

public override Task DateTimeOffset_Date_returns_datetime(bool async)
=> AssertTranslationFailed(() => base.DateTimeOffset_Date_returns_datetime(async));

// Sqlite does not support cross/outer apply
public override Task Correlated_collections_inner_subquery_predicate_references_outer_qsre(bool async) => null;

public override Task Correlated_collections_inner_subquery_selector_references_outer_qsre(bool async) => null;

public override Task Correlated_collections_nested_inner_subquery_references_outer_qsre_one_level_up(bool async) => null;

public override Task Correlated_collections_nested_inner_subquery_references_outer_qsre_two_levels_up(bool async) => null;

public override Task Outer_parameter_in_group_join_with_DefaultIfEmpty(bool async) => null;

public override Task Outer_parameter_in_join_key(bool async) => null;

public override Task Outer_parameter_in_join_key_inner_and_outer(bool async) => null;

public override Task Subquery_projecting_nullable_scalar_contains_nullable_value_needs_null_expansion(bool async) => null;

public override Task Subquery_projecting_nullable_scalar_contains_nullable_value_needs_null_expansion_negated(bool async) => null;

public override Task Subquery_projecting_non_nullable_scalar_contains_non_nullable_value_doesnt_need_null_expansion(bool async) => null;

public override Task Subquery_projecting_non_nullable_scalar_contains_non_nullable_value_doesnt_need_null_expansion_negated(bool async) => null;

public override async Task Negate_on_binary_expression(bool async)
{
await base.Negate_on_binary_expression(async);

AssertSql(
@"SELECT ""s"".""Id"", ""s"".""Banner"", ""s"".""Banner5"", ""s"".""InternalNumber"", ""s"".""Name""
FROM ""Squads"" AS ""s""
WHERE ""s"".""Id"" = -(""s"".""Id"" + ""s"".""Id"")");
}

public override async Task Negate_on_column(bool async)
{
await base.Negate_on_column(async);

AssertSql(
@"SELECT ""s"".""Id"", ""s"".""Banner"", ""s"".""Banner5"", ""s"".""InternalNumber"", ""s"".""Name""
FROM ""Squads"" AS ""s""
WHERE ""s"".""Id"" = -""s"".""Id""");
}

public override async Task Negate_on_like_expression(bool async)
{
await base.Negate_on_like_expression(async);

AssertSql(
@"SELECT ""s"".""Id"", ""s"".""Banner"", ""s"".""Banner5"", ""s"".""InternalNumber"", ""s"".""Name""
FROM ""Squads"" AS ""s""
WHERE ""s"".""Name"" IS NOT NULL AND NOT (""s"".""Name"" LIKE 'us%')");
}

public override async Task Select_datetimeoffset_comparison_in_projection(bool async)
{
await base.Select_datetimeoffset_comparison_in_projection(async);

AssertSql(
@"SELECT ""m"".""Timeline""
FROM ""Missions"" AS ""m""");
}

public override async Task Byte_array_contains_literal(bool async)
{
await base.Byte_array_contains_literal(async);

AssertSql(
@"SELECT ""s"".""Id"", ""s"".""Banner"", ""s"".""Banner5"", ""s"".""InternalNumber"", ""s"".""Name""
FROM ""Squads"" AS ""s""
WHERE instr(""s"".""Banner"", X'01') > 0");
}

public override async Task Byte_array_contains_parameter(bool async)
{
await base.Byte_array_contains_parameter(async);

AssertSql(
@"@__someByte_0='1' (DbType = String)
SELECT ""s"".""Id"", ""s"".""Banner"", ""s"".""Banner5"", ""s"".""InternalNumber"", ""s"".""Name""
FROM ""Squads"" AS ""s""
WHERE instr(""s"".""Banner"", char(@__someByte_0)) > 0");
}

public override async Task Byte_array_filter_by_length_literal(bool async)
{
await base.Byte_array_filter_by_length_literal(async);

AssertSql(@"SELECT ""s"".""Id"", ""s"".""Banner"", ""s"".""Banner5"", ""s"".""InternalNumber"", ""s"".""Name""
FROM ""Squads"" AS ""s""
WHERE length(""s"".""Banner"") = 1");
}

public override async Task Byte_array_filter_by_length_parameter(bool async)
{
await base.Byte_array_filter_by_length_parameter(async);

AssertSql(@"@__p_0='1' (DbType = String)
SELECT ""s"".""Id"", ""s"".""Banner"", ""s"".""Banner5"", ""s"".""InternalNumber"", ""s"".""Name""
FROM ""Squads"" AS ""s""
WHERE length(""s"".""Banner"") = @__p_0");
}

public override void Byte_array_filter_by_length_parameter_compiled()
{
base.Byte_array_filter_by_length_parameter_compiled();

AssertSql(
@"@__byteArrayParam='0x2A80' (Size = 2) (DbType = String)
SELECT COUNT(*)
FROM ""Squads"" AS ""s""
WHERE length(""s"".""Banner"") = length(@__byteArrayParam)");
}

public override async Task Byte_array_filter_by_SequenceEqual(bool async)
{
await base.Byte_array_filter_by_SequenceEqual(async);

AssertSql(@"@__byteArrayParam_0='0x0405060708' (Size = 5) (DbType = String)
SELECT ""s"".""Id"", ""s"".""Banner"", ""s"".""Banner5"", ""s"".""InternalNumber"", ""s"".""Name""
FROM ""Squads"" AS ""s""
WHERE ""s"".""Banner5"" = @__byteArrayParam_0");
}

[ConditionalTheory(Skip = "Issue#18844")]
public override Task TimeSpan_Hours(bool async) => base.TimeSpan_Hours(async);

[ConditionalTheory(Skip = "Issue#18844")]
public override Task TimeSpan_Minutes(bool async) => base.TimeSpan_Minutes(async);

[ConditionalTheory(Skip = "Issue#18844")]
public override Task TimeSpan_Seconds(bool async) => base.TimeSpan_Seconds(async);

[ConditionalTheory(Skip = "Issue#18844")]
public override Task TimeSpan_Milliseconds(bool async) => base.TimeSpan_Milliseconds(async);

[ConditionalTheory(Skip = "Issue#18844")]
public override Task Where_TimeSpan_Hours(bool async) => base.Where_TimeSpan_Hours(async);

[ConditionalTheory(Skip = "Issue#18844")]
public override Task Where_TimeSpan_Minutes(bool async) => base.Where_TimeSpan_Minutes(async);

[ConditionalTheory(Skip = "Issue#18844")]
public override Task Where_TimeSpan_Seconds(bool async) => base.Where_TimeSpan_Seconds(async);

[ConditionalTheory(Skip = "Issue#18844")]
public override Task Where_TimeSpan_Milliseconds(bool async) => base.Where_TimeSpan_Milliseconds(async);

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
}

0 comments on commit 230ac18

Please sign in to comment.