-
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 navigation in UserDefinedFunction (#30776)
* Fix navigation * add Visits_extention_childrens test
- Loading branch information
1 parent
3994ea9
commit f414770
Showing
2 changed files
with
97 additions
and
1 deletion.
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
95 changes: 95 additions & 0 deletions
95
test/EFCore.Tests/Query/Internal/NavigationExpandingExpressionVisitorTests.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,95 @@ | ||
// 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.Infrastructure.Internal; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
public class NavigationExpandingExpressionVisitorTests | ||
{ | ||
private class TestInterceptors : IInterceptors | ||
{ | ||
public TInterceptor Aggregate<TInterceptor>() | ||
where TInterceptor : class, IInterceptor | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
private class TestNavigationExpandingExpressionVisitor : NavigationExpandingExpressionVisitor | ||
{ | ||
public TestNavigationExpandingExpressionVisitor() | ||
: base( | ||
null, | ||
new QueryCompilationContext(new QueryCompilationContextDependencies( | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
new ExecutionStrategyTest.TestExecutionStrategy(new MyDemoContext()), | ||
new CurrentDbContext(new MyDemoContext()), | ||
null, | ||
null, | ||
new TestInterceptors() | ||
), false), | ||
null, | ||
null) | ||
{ | ||
} | ||
|
||
public Expression TestVisitExtension(Expression extensionExpression) | ||
{ | ||
return base.VisitExtension(extensionExpression); | ||
} | ||
} | ||
|
||
private class MyDemoContext : DbContext | ||
{ | ||
protected internal override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
optionsBuilder.UseInMemoryDatabase(databaseName: "test"); | ||
} | ||
} | ||
|
||
private class TestEntityQueryRootExpression : EntityQueryRootExpression | ||
{ | ||
public int VisitCounter = 0; | ||
|
||
public TestEntityQueryRootExpression(IAsyncQueryProvider asyncQueryProvider, IEntityType entityType) | ||
: base(asyncQueryProvider, entityType) | ||
{ | ||
} | ||
|
||
public TestEntityQueryRootExpression(IEntityType entityType) | ||
: base(entityType) | ||
{ | ||
} | ||
|
||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
{ | ||
VisitCounter++; | ||
return this; | ||
} | ||
|
||
} | ||
|
||
private class A | ||
{ | ||
public int B { get; set; } | ||
} | ||
|
||
[ConditionalFact] | ||
public void Visits_extention_childrens() | ||
{ | ||
var model = new Model(); | ||
var e = model.AddEntityType(typeof(A), false, ConfigurationSource.Explicit); | ||
var visitor = new TestNavigationExpandingExpressionVisitor(); | ||
var testExpression = new TestEntityQueryRootExpression(e); | ||
|
||
visitor.TestVisitExtension(testExpression); | ||
|
||
Assert.Equal(1, testExpression.VisitCounter); | ||
} | ||
} |