Skip to content

Commit

Permalink
Plumb CancellationToken through IsMoqSetupMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKotsenas committed Jun 12, 2024
1 parent 1e75c47 commit 23481a4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context)
SeparatedSyntaxList<ParameterSyntax> lambdaParameters = callbackLambda.ParameterList.Parameters;
if (lambdaParameters.Count == 0) return;

InvocationExpressionSyntax? setupInvocation = Helpers.FindSetupMethodFromCallbackInvocation(context.SemanticModel, callbackOrReturnsInvocation);
InvocationExpressionSyntax? setupInvocation = Helpers.FindSetupMethodFromCallbackInvocation(context.SemanticModel, callbackOrReturnsInvocation, context.CancellationToken);
InvocationExpressionSyntax? mockedMethodInvocation = Helpers.FindMockedMethodInvocationFromSetupMethod(setupInvocation);
if (mockedMethodInvocation == null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private async Task<Document> FixCallbackSignatureAsync(SyntaxNode root, Document
return document;
}

InvocationExpressionSyntax? setupMethodInvocation = Helpers.FindSetupMethodFromCallbackInvocation(semanticModel, callbackInvocation);
InvocationExpressionSyntax? setupMethodInvocation = Helpers.FindSetupMethodFromCallbackInvocation(semanticModel, callbackInvocation, cancellationToken);
Debug.Assert(setupMethodInvocation != null, nameof(setupMethodInvocation) + " != null");
IMethodSymbol[]? matchingMockedMethods = Helpers.GetAllMatchingMockedMethodSymbolsFromSetupMethodInvocation(semanticModel, setupMethodInvocation).ToArray();

Expand Down
10 changes: 4 additions & 6 deletions Source/Moq.Analyzers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ internal static class Helpers
{
private static readonly MoqMethodDescriptorBase MoqSetupMethodDescriptor = new MoqSetupMethodDescriptor();

internal static bool IsMoqSetupMethod(SemanticModel semanticModel, MemberAccessExpressionSyntax method)
internal static bool IsMoqSetupMethod(SemanticModel semanticModel, MemberAccessExpressionSyntax method, CancellationToken cancellationToken)
{
// TODO: Plumb cancellationToken through
CancellationToken cancellationToken = default;
return MoqSetupMethodDescriptor.IsMatch(semanticModel, method, cancellationToken);
}

Expand Down Expand Up @@ -42,12 +40,12 @@ internal static bool IsCallbackOrReturnInvocation(SemanticModel semanticModel, I
};
}

internal static InvocationExpressionSyntax? FindSetupMethodFromCallbackInvocation(SemanticModel semanticModel, ExpressionSyntax expression)
internal static InvocationExpressionSyntax? FindSetupMethodFromCallbackInvocation(SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken)
{
InvocationExpressionSyntax? invocation = expression as InvocationExpressionSyntax;
if (invocation?.Expression is not MemberAccessExpressionSyntax method) return null;
if (IsMoqSetupMethod(semanticModel, method)) return invocation;
return FindSetupMethodFromCallbackInvocation(semanticModel, method.Expression);
if (IsMoqSetupMethod(semanticModel, method, cancellationToken)) return invocation;
return FindSetupMethodFromCallbackInvocation(semanticModel, method.Expression, cancellationToken);
}

internal static InvocationExpressionSyntax? FindMockedMethodInvocationFromSetupMethod(InvocationExpressionSyntax? setupInvocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context)
{
InvocationExpressionSyntax? setupInvocation = (InvocationExpressionSyntax)context.Node;

if (setupInvocation.Expression is MemberAccessExpressionSyntax memberAccessExpression && Helpers.IsMoqSetupMethod(context.SemanticModel, memberAccessExpression))
if (setupInvocation.Expression is MemberAccessExpressionSyntax memberAccessExpression && Helpers.IsMoqSetupMethod(context.SemanticModel, memberAccessExpression, context.CancellationToken))
{
ExpressionSyntax? mockedMemberExpression = Helpers.FindMockedMemberExpressionFromSetupMethod(setupInvocation);
if (mockedMemberExpression == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context)
{
InvocationExpressionSyntax? setupInvocation = (InvocationExpressionSyntax)context.Node;

if (setupInvocation.Expression is MemberAccessExpressionSyntax memberAccessExpression && Helpers.IsMoqSetupMethod(context.SemanticModel, memberAccessExpression))
if (setupInvocation.Expression is MemberAccessExpressionSyntax memberAccessExpression && Helpers.IsMoqSetupMethod(context.SemanticModel, memberAccessExpression, context.CancellationToken))
{
ExpressionSyntax? mockedMemberExpression = Helpers.FindMockedMemberExpressionFromSetupMethod(setupInvocation);
if (mockedMemberExpression == null)
Expand Down

0 comments on commit 23481a4

Please sign in to comment.