protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            var remove        = NodeReplacement.RemoveAndExtractArguments("Select");
            var newExpression = GetNewExpression(expression, remove);

            return(GetNewExpression(newExpression, NodeReplacement.PrependArguments("NotContainNulls", remove.Arguments)));
        }
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            if (properties.VisitorName == nameof(DictionaryShouldContainPairAnalyzer.ShouldContainKeyAndContainValueSyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("ContainValue");
                var newExpression = GetNewExpression(expression, remove);

                var newArguments = GetArgumentsWithFirstAsPairIdentifierArgument(remove.Arguments);

                newExpression = GetNewExpression(newExpression, NodeReplacement.RenameAndRemoveFirstArgument("ContainKey", "Contain"));

                newExpression = GetNewExpression(newExpression, NodeReplacement.PrependArguments("Contain", newArguments));

                return(newExpression);
            }
            else if (properties.VisitorName == nameof(DictionaryShouldContainPairAnalyzer.ShouldContainValueAndContainKeySyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("ContainKey");
                var newExpression = GetNewExpression(expression, remove);

                var newArguments = GetArgumentsWithFirstAsPairIdentifierArgument(remove.Arguments);

                newExpression = GetNewExpression(newExpression, NodeReplacement.RenameAndRemoveFirstArgument("ContainValue", "Contain"));

                newExpression = GetNewExpression(newExpression, NodeReplacement.PrependArguments("Contain", newArguments));

                return(newExpression);
            }
            else
            {
                throw new InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
            }
        }
Exemplo n.º 3
0
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            var remove        = NodeReplacement.RemoveAndExtractArguments("OrderByDescending");
            var newExpression = GetNewExpression(expression, remove);

            newExpression = GetNewExpression(newExpression, NodeReplacement.RenameAndRemoveFirstArgument("Equal", "BeInDescendingOrder"));

            return(GetNewExpression(newExpression, NodeReplacement.PrependArguments("BeInDescendingOrder", remove.Arguments)));
        }
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            var newExpression = GetNewExpression(expression, NodeReplacement.RenameAndRemoveFirstArgument("HaveCount", "ContainSingle"));

            if (properties.VisitorName == nameof(CollectionShouldContainSingleAnalyzer.ShouldHaveCount1SyntaxVisitor))
            {
                return(newExpression);
            }
            else if (properties.VisitorName == nameof(CollectionShouldContainSingleAnalyzer.WhereShouldHaveCount1SyntaxVisitor))
            {
                var remove = NodeReplacement.RemoveAndExtractArguments("Where");
                newExpression = GetNewExpression(newExpression, remove);

                return(GetNewExpression(newExpression, NodeReplacement.PrependArguments("ContainSingle", remove.Arguments)));
            }
            throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
        }
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            var removeMethodContainingFirstLambda = NodeReplacement.RemoveAndExtractArguments("Select");
            var newExpression = GetNewExpression(expression, removeMethodContainingFirstLambda);

            var removeArgument = NodeReplacement.RemoveFirstArgument("Equal");

            newExpression = GetNewExpression(newExpression, removeArgument);

            var argumentInvocation = (InvocationExpressionSyntax)removeArgument.Argument.Expression;
            var identifier         = ((MemberAccessExpressionSyntax)argumentInvocation.Expression).Expression;

            var firstLambda  = (SimpleLambdaExpressionSyntax)removeMethodContainingFirstLambda.Arguments[0].Expression;
            var secondLambda = (SimpleLambdaExpressionSyntax)argumentInvocation.ArgumentList.Arguments[0].Expression;

            var newArguments = SyntaxFactory.SeparatedList <ArgumentSyntax>()
                               .Add(removeArgument.Argument.WithExpression(identifier))
                               .Add(removeArgument.Argument.WithExpression(CombineLambdas(firstLambda, secondLambda).NormalizeWhitespace()
                                                                           ));

            return(GetNewExpression(newExpression, NodeReplacement.PrependArguments("Equal", newArguments)));
        }