-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also simplify a == null ? a : null and various other cleanup
- Loading branch information
Showing
16 changed files
with
362 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
test/EFCore.Cosmos.FunctionalTests/Query/Translations/OperatorTranslationsCosmosTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// 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 OperatorTranslationsCosmosTest : OperatorTranslationsTestBase<BasicTypesQueryCosmosFixture> | ||
{ | ||
public OperatorTranslationsCosmosTest(BasicTypesQueryCosmosFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture) | ||
{ | ||
Fixture.TestSqlLoggerFactory.Clear(); | ||
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); | ||
} | ||
|
||
#region Conditional | ||
|
||
public override Task Conditional_uncoalesce_with_equality_left(bool async) | ||
=> Fixture.NoSyncTest( | ||
async, async a => | ||
{ | ||
await base.Conditional_uncoalesce_with_equality_left(a); | ||
|
||
AssertSql( | ||
""" | ||
SELECT VALUE c | ||
FROM root c | ||
WHERE (((c["Int"] = 9) ? null : c["Int"]) > 1) | ||
"""); | ||
}); | ||
|
||
public override Task Conditional_uncoalesce_with_equality_right(bool async) | ||
=> Fixture.NoSyncTest( | ||
async, async a => | ||
{ | ||
await base.Conditional_uncoalesce_with_equality_right(a); | ||
|
||
AssertSql( | ||
""" | ||
SELECT VALUE c | ||
FROM root c | ||
WHERE (((9 = c["Int"]) ? null : c["Int"]) > 1) | ||
"""); | ||
}); | ||
|
||
public override Task Conditional_uncoalesce_with_unequality_left(bool async) | ||
=> Fixture.NoSyncTest( | ||
async, async a => | ||
{ | ||
await base.Conditional_uncoalesce_with_unequality_left(a); | ||
|
||
AssertSql( | ||
""" | ||
SELECT VALUE c | ||
FROM root c | ||
WHERE (((c["Int"] != 9) ? c["Int"] : null) > 1) | ||
"""); | ||
}); | ||
|
||
public override Task Conditional_uncoalesce_with_inequality_right(bool async) | ||
=> Fixture.NoSyncTest( | ||
async, async a => | ||
{ | ||
await base.Conditional_uncoalesce_with_inequality_right(a); | ||
|
||
AssertSql( | ||
""" | ||
SELECT VALUE c | ||
FROM root c | ||
WHERE (((9 != c["Int"]) ? c["Int"] : null) > 1) | ||
"""); | ||
}); | ||
|
||
#endregion Conditional | ||
|
||
[ConditionalFact] | ||
public virtual void Check_all_tests_overridden() | ||
=> TestHelpers.AssertAllMethodsOverridden(GetType()); | ||
|
||
private void AssertSql(params string[] expected) | ||
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected); | ||
} |
7 changes: 7 additions & 0 deletions
7
test/EFCore.InMemory.FunctionalTests/Query/Translations/OperatorTranslationsInMemoryTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// 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 OperatorTranslationsInMemoryTest(BasicTypesQueryInMemoryFixture fixture) | ||
: OperatorTranslationsTestBase<BasicTypesQueryInMemoryFixture>(fixture); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
test/EFCore.Specification.Tests/Query/Translations/OperatorTranslationsTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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 abstract class OperatorTranslationsTestBase<TFixture>(TFixture fixture) : QueryTestBase<TFixture>(fixture) | ||
where TFixture : BasicTypesQueryFixtureBase, new() | ||
{ | ||
#region Conditional | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public virtual Task Conditional_simplifiable_equality(bool async) | ||
=> AssertQuery( | ||
async, | ||
// ReSharper disable once MergeConditionalExpression | ||
cs => cs.Set<NullableBasicTypesEntity>().Where(x => (x.Int == null ? null : x.Int) > 1)); | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public virtual Task Conditional_simplifiable_inequality(bool async) | ||
=> AssertQuery( | ||
async, | ||
// ReSharper disable once MergeConditionalExpression | ||
cs => cs.Set<NullableBasicTypesEntity>().Where(x => (x.Int != null ? x.Int : null) > 1)); | ||
|
||
// In relational providers, x == a ? null : x ("un-coalescing conditional") is translated to SQL NULLIF | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public virtual Task Conditional_uncoalesce_with_equality_left(bool async) | ||
=> AssertQuery( | ||
async, | ||
cs => cs.Set<BasicTypesEntity>().Where(x => (x.Int == 9 ? null : x.Int) > 1)); | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public virtual Task Conditional_uncoalesce_with_equality_right(bool async) | ||
=> AssertQuery( | ||
async, | ||
cs => cs.Set<BasicTypesEntity>().Where(x => (9 == x.Int ? null : x.Int) > 1)); | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public virtual Task Conditional_uncoalesce_with_unequality_left(bool async) | ||
=> AssertQuery( | ||
async, | ||
cs => cs.Set<BasicTypesEntity>().Where(x => (x.Int != 9 ? x.Int : null) > 1)); | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public virtual Task Conditional_uncoalesce_with_inequality_right(bool async) | ||
=> AssertQuery( | ||
async, | ||
cs => cs.Set<BasicTypesEntity>().Where(x => (9 != x.Int ? x.Int : null) > 1)); | ||
|
||
#endregion Conditional | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.