Пример #1
0
 public InvocationFixContextData Build(InvocationExpressionSyntax node)
 {
     using (_invocationContext.Enter())
     {
         Visit(node);
         return(_invocationContext.Current);
     }
 }
 public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)
 {
     using (_methodContext.Enter())
     {
         FindEmptySyntaxToken(node);
         node = base.VisitMethodDeclaration(node) as MethodDeclarationSyntax;
         return(CompleteVerifyAllStatements(node));
     }
 }
        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax invocationExpr)
        {
            using (_invocationContext.Enter(invocationExpr))
            {
                var memberAccessExpr = invocationExpr.Expression as MemberAccessExpressionSyntax;
                if (memberAccessExpr != null)
                {
                    var originalSymbolInfo = _originalSemantics.GetSymbolInfo(memberAccessExpr);

                    invocationExpr   = base.VisitInvocationExpression(invocationExpr) as InvocationExpressionSyntax;
                    memberAccessExpr = invocationExpr.Expression as MemberAccessExpressionSyntax;

                    var originalMemberSymbol = originalSymbolInfo.Symbol as IMethodSymbol ?? originalSymbolInfo.CandidateSymbols.OfType <IMethodSymbol>().FirstOrDefault();
                    if (originalMemberSymbol != null)
                    {
                        if (RhinoRecognizer.IsReturnMethod(originalMemberSymbol))
                        {
                            invocationExpr = invocationExpr.WithArgumentList(ReWriteArguments(invocationExpr));
                            if (_invocationContext.Current.UseAnyArgs)
                            {
                                return(invocationExpr.WithExpression(UseReturnsForAnyArgs(memberAccessExpr)));
                            }
                            else
                            {
                                return(invocationExpr.WithExpression(UseReturns(memberAccessExpr)));
                            }
                        }
                        if (RhinoRecognizer.IsExpectMethod(originalMemberSymbol) || RhinoRecognizer.IsStubMethod(originalMemberSymbol))
                        {
                            return(ExtractExpectAndStubInvocation(memberAccessExpr));
                        }
                        if (RhinoRecognizer.IsGenerateMockMethod(originalMemberSymbol) || RhinoRecognizer.IsGenerateStubMethod(originalMemberSymbol))
                        {
                            return(UseSubstituteFor(memberAccessExpr));
                        }
                        if (RhinoRecognizer.IsThrowMethod(originalMemberSymbol))
                        {
                            UseExceptionExtensions = true;
                            if (_invocationContext.Current.UseAnyArgs)
                            {
                                return(invocationExpr.WithExpression(UseThrowsForAnyArgs(memberAccessExpr)));
                            }
                            else
                            {
                                return(invocationExpr.WithExpression(UseThrows(memberAccessExpr)));
                            }
                        }
                        if (RhinoRecognizer.IsIgnoreArgumentsMethod(originalMemberSymbol) &&
                            invocationExpr.Expression is MemberAccessExpressionSyntax ignoreArgumentsMemberExpression &&
                            ignoreArgumentsMemberExpression.Expression is InvocationExpressionSyntax innerIgnoreArgumentsInvocationExpression)
                        {
                            return(innerIgnoreArgumentsInvocationExpression);
                        }
                        if (RhinoRecognizer.IsAnyRepeatOptionsMethod(originalMemberSymbol) &&
                            invocationExpr.Expression is MemberAccessExpressionSyntax repeatOptionMemberAccess &&
                            repeatOptionMemberAccess.Expression is MemberAccessExpressionSyntax repeatMemberAccess &&
                            repeatMemberAccess.Expression != null)
                        {
                            return(repeatMemberAccess.Expression);
                        }
                        if (RhinoRecognizer.IsOutRefProperty(originalMemberSymbol) &&
                            invocationExpr.Expression is MemberAccessExpressionSyntax outRefMemberExpression &&
                            outRefMemberExpression.Expression is InvocationExpressionSyntax outRefInnerInvocationExpression)
                        {
                            return(outRefInnerInvocationExpression);
                        }
                        if (RhinoRecognizer.IsVerifyAllExpectationsMethod(originalMemberSymbol))
                        {
                            return(UseReceivedOnMethodContext(invocationExpr));
                        }
                        if (RhinoRecognizer.IsAssertWasCalledMethod(originalMemberSymbol))
                        {
                            return(ExtractAssertCalledInvocation(memberAccessExpr, "AssertWasCalled", "Received"));
                        }
                        if (RhinoRecognizer.IsAssertWasNotCalledMethod(originalMemberSymbol))
                        {
                            return(ExtractAssertCalledInvocation(memberAccessExpr, "AssertWasNotCalled", "DidNotReceive"));
                        }
                        if (RhinoRecognizer.IsPropertyBehavior(originalMemberSymbol))
                        {
                            return(RemoveInvocation(invocationExpr));
                        }
                        if (RhinoRecognizer.IsWhenCalledMethod(originalMemberSymbol) &&
                            invocationExpr.Expression is MemberAccessExpressionSyntax whenCalledMemberAccess &&
                            invocationExpr.ArgumentList.Arguments.FirstOrDefault().Expression is SimpleLambdaExpressionSyntax whenCalledLambda)
                        {
                            return(UseInnerCallOrWhenDo(invocationExpr, whenCalledMemberAccess));
                        }
                    }
                }
                return(invocationExpr);
            }
        }