-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: convert NoMethodsInPropertySetupAnalyzer to IOperation #955
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
187a7c7
db78020
681e023
56866d6
962f7b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,21 @@ | |
| /// </summary> | ||
| internal ImmutableArray<IMethodSymbol> Mock1Setup => Mock1?.GetMembers("Setup").OfType<IMethodSymbol>().ToImmutableArray() ?? ImmutableArray<IMethodSymbol>.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets the methods for <c>Moq.Mock{T}.SetupGet</c>. | ||
| /// </summary> | ||
| internal ImmutableArray<IMethodSymbol> Mock1SetupGet => Mock1?.GetMembers("SetupGet").OfType<IMethodSymbol>().ToImmutableArray() ?? ImmutableArray<IMethodSymbol>.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets the methods for <c>Moq.Mock{T}.SetupSet</c>. | ||
| /// </summary> | ||
| internal ImmutableArray<IMethodSymbol> Mock1SetupSet => Mock1?.GetMembers("SetupSet").OfType<IMethodSymbol>().ToImmutableArray() ?? ImmutableArray<IMethodSymbol>.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets the methods for <c>Moq.Mock{T}.SetupProperty</c>. | ||
| /// </summary> | ||
| internal ImmutableArray<IMethodSymbol> Mock1SetupProperty => Mock1?.GetMembers("SetupProperty").OfType<IMethodSymbol>().ToImmutableArray() ?? ImmutableArray<IMethodSymbol>.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets the methods for <c>Moq.Mock{T}.SetupAdd</c>. | ||
| /// </summary> | ||
|
|
@@ -403,4 +418,15 @@ | |
| /// Gets the methods for <c>Moq.Times.Exactly</c>. | ||
| /// </summary> | ||
| internal ImmutableArray<IMethodSymbol> TimesExactly => Times?.GetMembers("Exactly").OfType<IMethodSymbol>().ToImmutableArray() ?? ImmutableArray<IMethodSymbol>.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets the interface <c>Microsoft.Extensions.Logging.ILogger</c>. | ||
| /// </summary> | ||
| internal INamedTypeSymbol? ILogger => TypeProvider.GetOrCreateTypeByMetadataName("Microsoft.Extensions.Logging.ILogger"); | ||
|
|
||
| /// <summary> | ||
| /// Gets the interface <c>Microsoft.Extensions.Logging.ILogger{T}</c>. | ||
| /// </summary> | ||
| internal INamedTypeSymbol? ILogger1 => TypeProvider.GetOrCreateTypeByMetadataName("Microsoft.Extensions.Logging.ILogger`1"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| } | ||
|
Check failure on line 432 in src/Common/WellKnown/MoqKnownSymbols.cs
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation for finding the mocked method call mixes
IOperationwithSyntaxNodeanalysis by falling back toFindMockedMethodInvocationFromSetupMethod. This partially defeats the purpose of refactoring toIOperation.Additionally, the
FindMockedMethodInvocationFromSetupMethodhelper only works for expression-bodied lambdas (x => x.Method()) and will fail for block-bodied lambdas (x => { return x.Method(); }), asLambdaExpressionSyntax.Bodywould be aBlockSyntax.You can implement this logic purely using the
IOperationtree, which will be more robust and align better with the refactoring goal. This also provides an opportunity to correctly handle block-bodied lambdas.