@@ -21,11 +21,27 @@ protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
2121 {
2222 get
2323 {
24+ yield return new CountShouldBe0SyntaxVisitor ( ) ;
25+ yield return new CountShouldBe1SyntaxVisitor ( ) ;
2426 yield return new CountShouldBeSyntaxVisitor ( ) ;
2527 }
2628 }
2729
28- private class CountShouldBeSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
30+ public class CountShouldBe0SyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
31+ {
32+ public CountShouldBe0SyntaxVisitor ( ) : base ( MemberValidator . MathodNotContainingLambda ( "Count" ) , MemberValidator . Should , MemberValidator . ArgumentIsLiteral ( "Be" , 0 ) )
33+ {
34+ }
35+ }
36+
37+ public class CountShouldBe1SyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
38+ {
39+ public CountShouldBe1SyntaxVisitor ( ) : base ( MemberValidator . MathodNotContainingLambda ( "Count" ) , MemberValidator . Should , MemberValidator . ArgumentIsLiteral ( "Be" , 1 ) )
40+ {
41+ }
42+ }
43+
44+ public class CountShouldBeSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
2945 {
3046 public CountShouldBeSyntaxVisitor ( ) : base ( MemberValidator . MathodNotContainingLambda ( "Count" ) , MemberValidator . Should , new MemberValidator ( "Be" ) )
3147 {
@@ -40,7 +56,19 @@ public class CollectionShouldHaveCountCodeFix : FluentAssertionsCodeFixProvider
4056
4157 protected override ExpressionSyntax GetNewExpression ( ExpressionSyntax expression , FluentAssertionsDiagnosticProperties properties )
4258 {
43- return GetNewExpression ( expression , NodeReplacement . Remove ( "Count" ) , NodeReplacement . Rename ( "Be" , "HaveCount" ) ) ;
59+ if ( properties . VisitorName == nameof ( CollectionShouldHaveCountAnalyzer . CountShouldBe0SyntaxVisitor ) )
60+ {
61+ return GetNewExpression ( expression , NodeReplacement . Remove ( "Count" ) , NodeReplacement . RenameAndRemoveFirstArgument ( "Be" , "BeEmpty" ) ) ;
62+ }
63+ else if ( properties . VisitorName == nameof ( CollectionShouldHaveCountAnalyzer . CountShouldBe1SyntaxVisitor ) )
64+ {
65+ return GetNewExpression ( expression , NodeReplacement . Remove ( "Count" ) , NodeReplacement . RenameAndRemoveFirstArgument ( "Be" , "ContainSingle" ) ) ;
66+ }
67+ else if ( properties . VisitorName == nameof ( CollectionShouldHaveCountAnalyzer . CountShouldBeSyntaxVisitor ) )
68+ {
69+ return GetNewExpression ( expression , NodeReplacement . Remove ( "Count" ) , NodeReplacement . Rename ( "Be" , "HaveCount" ) ) ;
70+ }
71+ throw new System . InvalidOperationException ( $ "Invalid visitor name - { properties . VisitorName } ") ;
4472 }
4573 }
4674}
0 commit comments