Skip to content

Commit 122dbcf

Browse files
committed
RavenDB-25423 non working field test
1 parent 77d6c72 commit 122dbcf

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Raven.CodeAnalysis.Test/BooleanMethodNegationTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)