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)));
        }
Exemple #2
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}");
            }
        }