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) { 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) { 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) { 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) { if (properties.VisitorName == nameof(CollectionShouldContainPropertyAnalyzer.AnyShouldBeTrueSyntaxVisitor)) { var remove = NodeReplacement.RemoveAndExtractArguments("Any"); var newExpression = GetNewExpression(expression, remove); return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeTrue", "Contain", remove.Arguments))); } else if (properties.VisitorName == nameof(CollectionShouldContainPropertyAnalyzer.WhereShouldNotBeEmptySyntaxVisitor)) { var remove = NodeReplacement.RemoveAndExtractArguments("Where"); var newExpression = GetNewExpression(expression, remove); return(GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("NotBeEmpty", "Contain", remove.Arguments))); } throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}"); }
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) { return(GetNewExpression(expression, new NodeReplacement.RenameAndRemoveInvocationOfMethodOnFirstArgumentNodeReplacement("HaveCount", "HaveSameCount"))); }
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"))); }
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) { 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(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}"); } }
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties) { switch (properties.VisitorName) { case nameof(ExceptionShouldThrowWithInnerExceptionAnalyzer.ShouldThrowWhichInnerExceptionShouldBeOfType): case nameof(ExceptionShouldThrowWithInnerExceptionAnalyzer.ShouldThrowExactlyWhichInnerExceptionShouldBeOfType): return(ReplaceBeOfTypeInnerException(expression, "Which")); case nameof(ExceptionShouldThrowWithInnerExceptionAnalyzer.ShouldThrowAndInnerExceptionShouldBeOfType): case nameof(ExceptionShouldThrowWithInnerExceptionAnalyzer.ShouldThrowExactlyAndInnerExceptionShouldBeOfType): return(ReplaceBeOfTypeInnerException(expression, "And")); case nameof(ExceptionShouldThrowWithInnerExceptionAnalyzer.ShouldThrowWhichInnerExceptionShouldBeAssignableTo): case nameof(ExceptionShouldThrowWithInnerExceptionAnalyzer.ShouldThrowExactlyWhichInnerExceptionShouldBeAssignableTo): return(ReplaceBeAssignableToInnerException(expression, "Which")); case nameof(ExceptionShouldThrowWithInnerExceptionAnalyzer.ShouldThrowAndInnerExceptionShouldBeAssignableTo): case nameof(ExceptionShouldThrowWithInnerExceptionAnalyzer.ShouldThrowExactlyAndInnerExceptionShouldBeAssignableTo): return(ReplaceBeAssignableToInnerException(expression, "And")); default: throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}"); } }
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties) { return(GetNewExpression(expression, NodeReplacement.RenameAndRemoveFirstArgument("HaveSameCount", "OnlyHaveUniqueItems"))); }
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties) { if (properties.VisitorName == nameof(CollectionShouldNotBeNullOrEmptyAnalyzer.ShouldNotBeNullAndNotBeEmptySyntaxVisitor)) { return(GetCombinedAssertions(expression, "NotBeEmpty", "NotBeNull")); } else if (properties.VisitorName == nameof(CollectionShouldNotBeNullOrEmptyAnalyzer.ShouldNotBeEmptyAndNotBeNullSyntaxVisitor)) { return(GetCombinedAssertions(expression, "NotBeNull", "NotBeEmpty")); } throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}"); }
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) { switch (properties.VisitorName) { case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowWhichMessageShouldContain): case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyWhichMessageShouldContain): return(ReplaceContainMessage(expression, "Which")); case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowAndMessageShouldContain): case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyAndMessageShouldContain): return(ReplaceContainMessage(expression, "And")); case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowWhichMessageShouldBe): case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyWhichMessageShouldBe): return(ReplaceBeMessage(expression, "Which")); case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowAndMessageShouldBe): case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyAndMessageShouldBe): return(ReplaceBeMessage(expression, "And")); case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowWhichMessageShouldStartWith): case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyWhichMessageShouldStartWith): return(ReplaceStartWithMessage(expression, "Which")); case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowAndMessageShouldStartWith): case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyAndMessageShouldStartWith): return(ReplaceStartWithMessage(expression, "And")); case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowWhichMessageShouldEndWith): case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyWhichMessageShouldEndWith): return(ReplaceEndWithMessage(expression, "Which")); case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowAndMessageShouldEndWith): case nameof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyAndMessageShouldEndWith): return(ReplaceEndWithMessage(expression, "And")); default: 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))); }
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) { throw new System.NotImplementedException(); }
protected abstract ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties);
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties) { return(GetNewExpression(expression, NodeReplacement.RenameAndRemoveFirstArgument("BeGreaterThan", "BePositive"))); }
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}"); }
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) { var remove = new NodeReplacement.RemoveAndExtractArgumentsNodeReplacement("Contains"); var newExpression = GetNewExpression(expression, remove); return(GetNewExpression(newExpression, new NodeReplacement.RenameAndPrependArgumentsNodeReplacement("BeFalse", "NotContain", remove.Arguments))); }
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 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}"); }