@@ -21,11 +21,27 @@ protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
21
21
{
22
22
get
23
23
{
24
+ yield return new CountShouldBe0SyntaxVisitor ( ) ;
25
+ yield return new CountShouldBe1SyntaxVisitor ( ) ;
24
26
yield return new CountShouldBeSyntaxVisitor ( ) ;
25
27
}
26
28
}
27
29
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
29
45
{
30
46
public CountShouldBeSyntaxVisitor ( ) : base ( MemberValidator . MathodNotContainingLambda ( "Count" ) , MemberValidator . Should , new MemberValidator ( "Be" ) )
31
47
{
@@ -40,7 +56,19 @@ public class CollectionShouldHaveCountCodeFix : FluentAssertionsCodeFixProvider
40
56
41
57
protected override ExpressionSyntax GetNewExpression ( ExpressionSyntax expression , FluentAssertionsDiagnosticProperties properties )
42
58
{
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 } ") ;
44
72
}
45
73
}
46
74
}
0 commit comments