@@ -70,6 +70,72 @@ void M()
7070 } ) ;
7171 }
7272
73+ [ TestMethod ]
74+ public void ShouldReportDiagnosticOnNegatedBooleanMethod_param ( )
75+ {
76+ const string input = @"
77+ class C
78+ {
79+ private bool HasPermission()
80+ {
81+ return false;
82+ }
83+
84+ static void M(C c)
85+ {
86+ if (!c.HasPermission())
87+ {
88+ }
89+ }
90+ }" ;
91+ VerifyCSharpDiagnostic ( input , new DiagnosticResult
92+ {
93+ Id = DiagnosticIds . BooleanMethodNegation ,
94+ Message = "Negated boolean method 'HasPermission' conditions should be rewritten as HasPermission(...) == false" ,
95+ Severity = DiagnosticSeverity . Error ,
96+ Locations =
97+ [
98+ new DiagnosticResultLocation ( "Test0.cs" , 11 , 13 )
99+ ]
100+ } ) ;
101+ }
102+
103+ [ TestMethod ]
104+ public void ShouldReportDiagnosticOnNegatedBooleanMethod_field ( )
105+ {
106+ const string input = @"
107+ class C
108+ {
109+ private bool HasPermission()
110+ {
111+ return false;
112+ }
113+ }
114+
115+ class D
116+ {
117+ private C _c;
118+
119+ void M()
120+ {
121+ if (!_c.HasPermission())
122+ {
123+ }
124+ }
125+ }
126+ " ;
127+ VerifyCSharpDiagnostic ( input , new DiagnosticResult
128+ {
129+ Id = DiagnosticIds . BooleanMethodNegation ,
130+ Message = "Negated boolean method 'HasPermission' conditions should be rewritten as HasPermission(...) == false" ,
131+ Severity = DiagnosticSeverity . Error ,
132+ Locations =
133+ [
134+ new DiagnosticResultLocation ( "Test0.cs" , 11 , 13 )
135+ ]
136+ } ) ;
137+ }
138+
73139 [ TestMethod ]
74140 public void ShouldNotReportDiagnosticOnNonNegatedBooleanMethod ( )
75141 {
0 commit comments