protected override void AnalyzeAssertInvocation(SyntaxNodeAnalysisContext context,
                                                        InvocationExpressionSyntax invocationSyntax, IMethodSymbol methodSymbol)
        {
            if (!AssertExpressionHelper.TryGetActualAndConstraintExpressions(invocationSyntax,
                                                                             out _, out var constraintExpression))
            {
                return;
            }

            var constraintParts = AssertExpressionHelper.SplitConstraintByOperators(constraintExpression);

            foreach (var constraintPart in constraintParts)
            {
                // e.g. Is.EqualTo(expected).IgnoreCase
                // Need to check type of expected
                if (constraintPart is MemberAccessExpressionSyntax ignoreCaseAccessSyntax)
                {
                    var expectedType = GetExpectedTypeSymbol(ignoreCaseAccessSyntax, context);

                    if (expectedType == null)
                    {
                        return;
                    }

                    if (!IsTypeSupported(expectedType))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(
                                                     descriptor,
                                                     ignoreCaseAccessSyntax.Name.GetLocation()));
                    }
                }
            }
        }
Beispiel #2
0
        protected override void AnalyzeAssertInvocation(SyntaxNodeAnalysisContext context,
                                                        InvocationExpressionSyntax assertExpression, IMethodSymbol methodSymbol)
        {
            if (!AssertExpressionHelper.TryGetActualAndConstraintExpressions(assertExpression,
                                                                             out var actualExpression, out var constraintExpression))
            {
                return;
            }

            var expectedExpressions     = AssertExpressionHelper.GetExpectedArguments(constraintExpression, context.SemanticModel);
            var sameExpectedExpressions = expectedExpressions.Where(e => e.expectedArgument.IsEquivalentTo(actualExpression));

            foreach (var(expected, _) in sameExpectedExpressions)
            {
                context.ReportDiagnostic(Diagnostic.Create(
                                             descriptor,
                                             expected.GetLocation(),
                                             expected.ToString()));
            }
        }