protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            if (properties.VisitorName == nameof(StringShouldNotBeNullOrEmptyAnalyzer.StringShouldNotBeNullAndNotBeEmptySyntaxVisitor))
            {
                return(GetCombinedAssertions(expression, "NotBeEmpty", "NotBeNull"));
            }
            else if (properties.VisitorName == nameof(StringShouldNotBeNullOrEmptyAnalyzer.StringShouldNotBeEmptyAndNotBeNullSyntaxVisitor))
            {
                return(GetCombinedAssertions(expression, "NotBeNull", "NotBeEmpty"));
            }
            else if (properties.VisitorName == nameof(StringShouldNotBeNullOrEmptyAnalyzer.StringIsNullOrEmptyShouldBeFalseSyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("IsNullOrEmpty");
                var newExpression = GetNewExpression(expression, remove);

                var rename = NodeReplacement.Rename("BeFalse", "NotBeNullOrEmpty");
                newExpression = GetNewExpression(newExpression, rename);

                var stringKeyword = newExpression.DescendantNodes().OfType <PredefinedTypeSyntax>().Single();
                var subject       = remove.Arguments.First().Expression;

                return(newExpression.ReplaceNode(stringKeyword, subject.WithTriviaFrom(stringKeyword)));
            }
            throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
        }
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            var remove        = NodeReplacement.RemoveAndExtractArguments("EndsWith");
            var newExpression = GetNewExpression(expression, remove);

            return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeTrue", "EndWith", remove.Arguments)));
        }
        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)));
        }
        private ExpressionSyntax GetCombinedAssertions(ExpressionSyntax expression, string removeMethod, string renameMethod)
        {
            var remove        = NodeReplacement.RemoveAndExtractArguments(removeMethod);
            var newExpression = GetNewExpression(expression, NodeReplacement.RemoveMethodBefore(removeMethod), remove);

            return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments(renameMethod, "NotBeNullOrEmpty", remove.Arguments)));
        }
Example #5
0
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            if (properties.VisitorName == nameof(NumericShouldBeInRangeAnalyzer.BeGreaterOrEqualToAndBeLessOrEqualToSyntaxVisitor))
            {
                var removeLess    = NodeReplacement.RemoveAndExtractArguments("BeLessOrEqualTo");
                var newExpression = GetNewExpression(expression, removeLess);

                var renameGreater = NodeReplacement.RenameAndExtractArguments("BeGreaterOrEqualTo", "BeInRange");
                newExpression = GetNewExpression(newExpression, renameGreater);

                var arguments = renameGreater.Arguments.InsertRange(1, removeLess.Arguments);

                return(GetNewExpression(newExpression, NodeReplacement.WithArguments("BeInRange", arguments)));
            }
            else if (properties.VisitorName == nameof(NumericShouldBeInRangeAnalyzer.BeLessOrEqualToAndBeGreaterOrEqualToSyntaxVisitor))
            {
                var removeGreater = NodeReplacement.RemoveAndExtractArguments("BeGreaterOrEqualTo");
                var newExpression = GetNewExpression(expression, removeGreater);

                var renameLess = NodeReplacement.RenameAndExtractArguments("BeLessOrEqualTo", "BeInRange");
                newExpression = GetNewExpression(newExpression, renameLess);

                var arguments = removeGreater.Arguments.InsertRange(1, renameLess.Arguments);

                return(GetNewExpression(newExpression, NodeReplacement.WithArguments("BeInRange", arguments)));
            }
            throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
        }
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            if (properties.VisitorName == nameof(CollectionShouldHaveElementAtAnalyzer.ElementAtIndexShouldBeSyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("ElementAt");
                var newExpression = GetNewExpression(expression, remove);

                return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("Be", "HaveElementAt", remove.Arguments)));
            }
            else if (properties.VisitorName == nameof(CollectionShouldHaveElementAtAnalyzer.IndexerShouldBeSyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndRetrieveIndexerArguments("Should");
                var newExpression = GetNewExpression(expression, remove);

                return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("Be", "HaveElementAt", remove.Arguments)));
            }
            else if (properties.VisitorName == nameof(CollectionShouldHaveElementAtAnalyzer.SkipFirstShouldBeSyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("Skip");
                var newExpression = GetNewExpression(expression, remove, NodeReplacement.Remove("First"));

                return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("Be", "HaveElementAt", remove.Arguments)));
            }
            throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
        }
Example #7
0
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            if (properties.VisitorName == nameof(DictionaryShouldContainPairAnalyzer.ShouldContainKeyAndContainValueSyntaxVisitor))
            {
                var renameKeyArguments   = NodeReplacement.RenameAndExtractArguments("ContainKey", "Contain");
                var removeValueArguments = NodeReplacement.RemoveAndExtractArguments("ContainValue");
                var newExpression        = GetNewExpression(expression, NodeReplacement.RemoveMethodBefore("ContainValue"), renameKeyArguments, removeValueArguments);

                var newArguments = MergeContainKeyAndContainValueArguments(renameKeyArguments.Arguments, removeValueArguments.Arguments);

                return(GetNewExpression(newExpression, NodeReplacement.WithArguments("Contain", newArguments)));
            }
            else if (properties.VisitorName == nameof(DictionaryShouldContainPairAnalyzer.ShouldContainValueAndContainKeySyntaxVisitor))
            {
                var removeKeyArguments   = NodeReplacement.RemoveAndExtractArguments("ContainKey");
                var renameValueArguments = NodeReplacement.RenameAndExtractArguments("ContainValue", "Contain");
                var newExpression        = GetNewExpression(expression, NodeReplacement.RemoveMethodBefore("ContainKey"), removeKeyArguments, renameValueArguments);

                var newArguments = MergeContainKeyAndContainValueArguments(removeKeyArguments.Arguments, renameValueArguments.Arguments);

                return(GetNewExpression(newExpression, NodeReplacement.WithArguments("Contain", newArguments)));
            }
            else
            {
                throw new InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
            }
        }
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            if (properties.VisitorName == nameof(CollectionShouldNotContainPropertyAnalyzer.AnyShouldBeFalseSyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("Any");
                var newExpression = GetNewExpression(expression, remove);

                return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeFalse", "NotContain", remove.Arguments)));
            }
            else if (properties.VisitorName == nameof(CollectionShouldNotContainPropertyAnalyzer.WhereShouldBeEmptySyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("Where");
                var newExpression = GetNewExpression(expression, remove);

                return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeEmpty", "NotContain", remove.Arguments)));
            }

            /*
             * else if (properties.VisitorName == nameof(CollectionShouldNotContainPropertyAnalyzer.ShouldOnlyContainNotSyntaxVisitor))
             * {
             *  return GetNewExpression(expression, NodeReplacement.RenameAndNegateLambda("OnlyContain", "NotContain"));
             * }
             */
            throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
        }
        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}");
            }
        }
Example #10
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)));
        }
Example #11
0
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            var remove        = NodeReplacement.RemoveAndExtractArguments("IsNullOrEmpty");
            var newExpression = GetNewExpression(expression, remove);

            var rename = NodeReplacement.Rename("BeTrue", "BeNullOrEmpty");

            newExpression = GetNewExpression(newExpression, rename);

            var stringKeyword = newExpression.DescendantNodes().OfType <PredefinedTypeSyntax>().Single();
            var subject       = remove.Arguments.First().Expression;

            return(newExpression.ReplaceNode(stringKeyword, subject.WithTriviaFrom(stringKeyword)));
        }
Example #12
0
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            var remove        = NodeReplacement.RemoveAndExtractArguments("Abs");
            var newExpression = GetNewExpression(expression, remove);

            var subtractExpression = (BinaryExpressionSyntax)remove.Arguments[0].Expression;

            var actual   = subtractExpression.Right as IdentifierNameSyntax;
            var expected = subtractExpression.Left;

            newExpression = GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeLessOrEqualTo", "BeApproximately", new SeparatedSyntaxList <ArgumentSyntax>().Add(SyntaxFactory.Argument(expected))));

            newExpression = RenameIdentifier(newExpression, "Math", actual.Identifier.Text);

            return(newExpression);
        }
        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)
        {
            if (properties.VisitorName == nameof(CollectionShouldNotBeNullOrEmptyAnalyzer.ShouldNotBeNullAndNotBeEmptySyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("NotBeEmpty");
                var newExpression = GetNewExpression(expression, remove);

                return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("NotBeNull", "NotBeNullOrEmpty", remove.Arguments)));
            }
            else if (properties.VisitorName == nameof(CollectionShouldNotBeNullOrEmptyAnalyzer.ShouldNotBeEmptyAndNotBeNullSyntaxVisitor))
            {
                var remove        = NodeReplacement.RemoveAndExtractArguments("NotBeNull");
                var newExpression = GetNewExpression(expression, remove);

                return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("NotBeEmpty", "NotBeNullOrEmpty", 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)));
        }