示例#1
0
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            var remove        = NodeReplacement.Remove("Length");
            var newExpression = GetNewExpression(expression, remove);

            return(GetNewExpression(newExpression, NodeReplacement.Rename("Be", "HaveLength")));
        }
        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}");
        }
示例#3
0
        private ExpressionSyntax ReplaceBeMessage(ExpressionSyntax expression, string whichOrAnd)
        {
            var replacements = new[]
            {
                NodeReplacement.Remove(whichOrAnd),
                NodeReplacement.Remove("Message"),
                NodeReplacement.RemoveOccurrence("Should", occurrence: 2),
                NodeReplacement.Rename("Be", "WithMessage")
            };

            return(GetNewExpression(expression, replacements));
        }
示例#4
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)));
        }
        protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
        {
            switch (properties.VisitorName)
            {
            case nameof(CollectionShouldBeEmptyAnalyzer.AnyShouldBeFalseSyntaxVisitor):
                return(GetNewExpression(expression, NodeReplacement.Remove("Any"), NodeReplacement.Rename("BeFalse", "BeEmpty")));

            case nameof(CollectionShouldBeEmptyAnalyzer.ShouldHaveCount0SyntaxVisitor):
                return(GetNewExpression(expression, new HaveCountNodeReplacement()));

            default:
                throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
            }
        }
 protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
 {
     if (properties.VisitorName == nameof(CollectionShouldHaveCountAnalyzer.CountShouldBe0SyntaxVisitor))
     {
         return(GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.RenameAndRemoveFirstArgument("Be", "BeEmpty")));
     }
     else if (properties.VisitorName == nameof(CollectionShouldHaveCountAnalyzer.CountShouldBe1SyntaxVisitor))
     {
         return(GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.RenameAndRemoveFirstArgument("Be", "ContainSingle")));
     }
     else if (properties.VisitorName == nameof(CollectionShouldHaveCountAnalyzer.CountShouldBeSyntaxVisitor))
     {
         return(GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.Rename("Be", "HaveCount")));
     }
     throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
 }
 protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
 {
     return(GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.Rename("BeLessThan", "HaveCountLessThan")));
 }
 protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
 {
     return(GetNewExpression(expression, NodeReplacement.Remove("Any"), NodeReplacement.Rename("BeTrue", "NotBeEmpty")));
 }