-
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.
Fix to #19900 - Query/Test: add automatic null propagation for AsserQ…
…uery baselines (part1) Added visitor that injects Maybe methods for all non-scalar member accesses. Also refactored Maybe methods to be more composible and so that when used manually, they don't require type arguments to be specified.
- Loading branch information
Showing
13 changed files
with
455 additions
and
1,082 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
916 changes: 232 additions & 684 deletions
916
test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
Large diffs are not rendered by default.
Oops, something went wrong.
111 changes: 46 additions & 65 deletions
111
test/EFCore.Specification.Tests/Query/FunkyDataQueryTestBase.cs
Large diffs are not rendered by default.
Oops, something went wrong.
327 changes: 70 additions & 257 deletions
327
test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
33 changes: 33 additions & 0 deletions
33
test/EFCore.Specification.Tests/TestUtilities/ExpectedQueryRewritingVisitor.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,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 System; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.EntityFrameworkCore.TestUtilities | ||
{ | ||
public class ExpectedQueryRewritingVisitor : ExpressionVisitor | ||
{ | ||
private static readonly MethodInfo _maybeMethod | ||
= typeof(QueryTestExtensions).GetMethod(nameof(QueryTestExtensions.Maybe)); | ||
|
||
protected override Expression VisitMember(MemberExpression memberExpression) | ||
{ | ||
if (!memberExpression.Type.IsValueType | ||
&& !memberExpression.Type.IsNullableValueType() | ||
&& memberExpression.Expression != null) | ||
{ | ||
var expression = Visit(memberExpression.Expression); | ||
|
||
var lambdaParameter = Expression.Parameter(expression.Type, "x"); | ||
var lambda = Expression.Lambda(memberExpression.Update(lambdaParameter), lambdaParameter); | ||
var method = _maybeMethod.MakeGenericMethod(expression.Type, memberExpression.Type); | ||
|
||
return Expression.Call(method, expression, lambda); | ||
} | ||
|
||
return base.VisitMember(memberExpression); | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
test/EFCore.Specification.Tests/TestUtilities/QueryTestExtensions.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,28 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Microsoft.EntityFrameworkCore.TestUtilities | ||
{ | ||
public static class QueryTestExtensions | ||
{ | ||
public static TResult Maybe<TSource, TResult>(this TSource caller, Func<TSource, TResult> result) | ||
where TResult : class | ||
=> caller == null ? null : result(caller); | ||
|
||
public static TResult? MaybeScalar<TSource, TResult>(this TSource caller, Func<TSource, TResult> result) | ||
where TResult : struct | ||
=> caller != null ? (TResult?)result(caller) : null; | ||
|
||
public static TResult? MaybeScalar<TSource, TResult>(this TSource caller, Func<TSource, TResult?> result) | ||
where TResult : struct | ||
=> caller != null ? result(caller) : null; | ||
|
||
public static IEnumerable<TResult> MaybeDefaultIfEmpty<TResult>(this IEnumerable<TResult> caller) | ||
where TResult : class | ||
=> caller == null ? new List<TResult> { default } : caller.DefaultIfEmpty(); | ||
} | ||
} |
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