Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor method/member translation tests into their own suite #35319

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,031 changes: 36 additions & 1,995 deletions test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.BasicTypesModel;

namespace Microsoft.EntityFrameworkCore.Query.Translations;

public class BasicTypesQueryCosmosFixture : BasicTypesQueryFixtureBase
{
protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;

public TestSqlLoggerFactory TestSqlLoggerFactory
=> (TestSqlLoggerFactory)ListLoggerFactory;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> builder.ConfigureWarnings(o => o.Ignore(CosmosEventId.NoPartitionKeyDefined));
roji marked this conversation as resolved.
Show resolved Hide resolved

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

modelBuilder.Entity<BasicTypesEntity>().ToContainer(nameof(BasicTypesEntity));
modelBuilder.Entity<NullableBasicTypesEntity>().ToContainer(nameof(NullableBasicTypesEntity));
}

public Task NoSyncTest(bool async, Func<bool, Task> testCode)
=> CosmosTestHelpers.Instance.NoSyncTest(async, testCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.Query.Translations;

public class EnumTranslationsCosmosTest : EnumTranslationsTestBase<BasicTypesQueryCosmosFixture>
{
public EnumTranslationsCosmosTest(BasicTypesQueryCosmosFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture)
{
Fixture.TestSqlLoggerFactory.Clear();
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

#region Equality

public override Task Equality_to_constant(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Equality_to_constant(a);

AssertSql(
"""
SELECT VALUE c
FROM root c
WHERE (c["Enum"] = 0)
""");
});

public override Task Equality_to_parameter(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Equality_to_parameter(a);

AssertSql(
"""
@basicEnum=?

SELECT VALUE c
FROM root c
WHERE (c["Enum"] = @basicEnum)
""");
});

public override Task Equality_nullable_enum_to_constant(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Equality_nullable_enum_to_constant(a);

AssertSql(
"""
SELECT VALUE c
FROM root c
WHERE (c["Enum"] = 0)
""");
});

public override Task Equality_nullable_enum_to_parameter(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Equality_nullable_enum_to_parameter(a);

AssertSql(
"""
@basicEnum=?

SELECT VALUE c
FROM root c
WHERE (c["Enum"] = @basicEnum)
""");
});

public override Task Equality_nullable_enum_to_null_constant(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Equality_nullable_enum_to_null_constant(a);

AssertSql(
"""
SELECT VALUE c
FROM root c
WHERE (c["Enum"] = null)
""");
});

public override Task Equality_nullable_enum_to_null_parameter(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Equality_nullable_enum_to_null_parameter(a);

AssertSql(
"""
@basicEnum=?

SELECT VALUE c
FROM root c
WHERE (c["Enum"] = @basicEnum)
""");
});

public override Task Equality_nullable_enum_to_nullable_parameter(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Equality_nullable_enum_to_nullable_parameter(a);

AssertSql(
"""
@basicEnum=?

SELECT VALUE c
FROM root c
WHERE (c["Enum"] = @basicEnum)
""");
});

#endregion Equality

public override Task Bitwise_and_enum_constant(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Bitwise_and_enum_constant(a);

AssertSql(
"""
SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] & 1) > 0)
""",
//
"""
SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] & 1) = 1)
""");
});

public override async Task Bitwise_and_integral_constant(bool async)
{
// Always throws for sync.
if (async)
{
// Cosmos client evaluation. Issue #17246.
await AssertTranslationFailed(() => base.Bitwise_and_integral_constant(async));

AssertSql(
"""
SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] & 8) = 8)
""");
}
}

public override Task Bitwise_and_nullable_enum_with_constant(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Bitwise_and_nullable_enum_with_constant(a);

AssertSql(
"""
SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] & 8) > 0)
""");
});

public override Task Where_bitwise_and_nullable_enum_with_null_constant(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Where_bitwise_and_nullable_enum_with_null_constant(a);

AssertSql(
"""
SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] & null) > 0)
""");
});

public override Task Where_bitwise_and_nullable_enum_with_non_nullable_parameter(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Where_bitwise_and_nullable_enum_with_non_nullable_parameter(a);

AssertSql(
"""
@flagsEnum=?

SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] & @flagsEnum) > 0)
""");
});

public override Task Where_bitwise_and_nullable_enum_with_nullable_parameter(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Where_bitwise_and_nullable_enum_with_nullable_parameter(a);

AssertSql(
"""
@flagsEnum=?

SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] & @flagsEnum) > 0)
""",
//
"""
@flagsEnum=?

SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] & @flagsEnum) > 0)
""");
});

public override Task Bitwise_or(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Bitwise_or(a);

AssertSql(
"""
SELECT VALUE c
FROM root c
WHERE ((c["FlagsEnum"] | 8) > 0)
""");
});

public override Task Bitwise_projects_values_in_select(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Bitwise_projects_values_in_select(a);

AssertSql(
"""
SELECT VALUE
{
"BitwiseTrue" : ((c["FlagsEnum"] & 8) = 8),
"BitwiseFalse" : ((c["FlagsEnum"] & 8) = 4),
"BitwiseValue" : (c["FlagsEnum"] & 8)
}
FROM root c
WHERE ((c["FlagsEnum"] & 8) = 8)
OFFSET 0 LIMIT 1
""");
});

// #35317
public override Task HasFlag(bool async)
=> AssertTranslationFailed(() => base.HasFlag(async));

// #35317
public override Task HasFlag_with_non_nullable_parameter(bool async)
=> AssertTranslationFailed(() => base.HasFlag(async));

// #35317
public override Task HasFlag_with_nullable_parameter(bool async)
=> AssertTranslationFailed(() => base.HasFlag(async));

[ConditionalFact]
public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());

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