Skip to content

Commit 07a6f35

Browse files
committed
Convert naming rules to the new helpers
1 parent 4981654 commit 07a6f35

21 files changed

Lines changed: 567 additions & 1003 deletions

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/NamingRules/SA1300CSharp7UnitTests.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace StyleCop.Analyzers.Test.CSharp7.NamingRules
88
using StyleCop.Analyzers.Test.NamingRules;
99
using TestHelper;
1010
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.NamingRules.SA1300ElementMustBeginWithUpperCaseLetter,
13+
StyleCop.Analyzers.NamingRules.RenameToUpperCaseCodeFixProvider>;
1114

1215
public class SA1300CSharp7UnitTests : SA1300UnitTests
1316
{
@@ -24,7 +27,7 @@ void LocalFunction()
2427
}
2528
}";
2629

27-
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
30+
await VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
2831
}
2932

3033
[Fact]
@@ -49,11 +52,8 @@ void LocalFunction()
4952
}
5053
}";
5154

52-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("localFunction").WithLocation(5, 14);
53-
54-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
55-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
56-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
55+
DiagnosticResult expected = Diagnostic().WithArguments("localFunction").WithLocation(5, 14);
56+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
5757
}
5858

5959
[Fact]
@@ -83,11 +83,8 @@ void LocalFunction1()
8383
}
8484
}";
8585

86-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("localFunction").WithLocation(5, 14);
87-
88-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
89-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
90-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
86+
DiagnosticResult expected = Diagnostic().WithArguments("localFunction").WithLocation(5, 14);
87+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
9188
}
9289
}
9390
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/NamingRules/SA1305CSharp7UnitTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.NamingRules
88
using StyleCop.Analyzers.Test.NamingRules;
99
using TestHelper;
1010
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier<StyleCop.Analyzers.NamingRules.SA1305FieldNamesMustNotUseHungarianNotation>;
1112

1213
public class SA1305CSharp7UnitTests : SA1305UnitTests
1314
{
@@ -25,13 +26,13 @@ public void TestMethod()
2526

2627
DiagnosticResult[] expected =
2728
{
28-
this.CSharpDiagnostic().WithLocation(5, 14).WithArguments("variable", "baR"),
29-
this.CSharpDiagnostic().WithLocation(5, 19).WithArguments("variable", "caRe"),
30-
this.CSharpDiagnostic().WithLocation(5, 25).WithArguments("variable", "daRE"),
31-
this.CSharpDiagnostic().WithLocation(5, 31).WithArguments("variable", "fAre"),
29+
Diagnostic().WithLocation(5, 14).WithArguments("variable", "baR"),
30+
Diagnostic().WithLocation(5, 19).WithArguments("variable", "caRe"),
31+
Diagnostic().WithLocation(5, 25).WithArguments("variable", "daRE"),
32+
Diagnostic().WithLocation(5, 31).WithArguments("variable", "fAre"),
3233
};
3334

34-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
35+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
3536
}
3637

3738
[Fact]
@@ -50,10 +51,10 @@ void LocalFunction(bool abX)
5051

5152
DiagnosticResult[] expected =
5253
{
53-
this.CSharpDiagnostic().WithArguments("parameter", "abX").WithLocation(6, 33),
54+
Diagnostic().WithArguments("parameter", "abX").WithLocation(6, 33),
5455
};
5556

56-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
57+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
5758
}
5859

5960
[Fact]
@@ -70,7 +71,7 @@ void LocalFunction(bool abX)
7071
}
7172
}";
7273

73-
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
74+
await VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
7475
}
7576
}
7677
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/NamingRules/SA1312CSharp7UnitTests.cs

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace StyleCop.Analyzers.Test.CSharp7.NamingRules
88
using StyleCop.Analyzers.Test.NamingRules;
99
using TestHelper;
1010
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.NamingRules.SA1312VariableNamesMustBeginWithLowerCaseLetter,
13+
StyleCop.Analyzers.NamingRules.RenameToLowerCaseCodeFixProvider>;
1114

1215
public class SA1312CSharp7UnitTests : SA1312UnitTests
1316
{
@@ -26,12 +29,10 @@ public void MethodName()
2629

2730
DiagnosticResult[] expected =
2831
{
29-
this.CSharpDiagnostic().WithArguments("Bar").WithLocation(5, 35),
30-
this.CSharpDiagnostic().WithArguments("Par").WithLocation(7, 35),
32+
Diagnostic().WithArguments("Bar").WithLocation(5, 35),
33+
Diagnostic().WithArguments("Par").WithLocation(7, 35),
3134
};
3235

33-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
34-
3536
var fixedCode = @"public class TypeName
3637
{
3738
public void MethodName()
@@ -42,8 +43,7 @@ public void MethodName()
4243
}
4344
}";
4445

45-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
46-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
46+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
4747
}
4848

4949
[Fact]
@@ -59,12 +59,10 @@ public void MethodName()
5959

6060
DiagnosticResult[] expected =
6161
{
62-
this.CSharpDiagnostic().WithArguments("Bar").WithLocation(5, 14),
63-
this.CSharpDiagnostic().WithArguments("Par").WithLocation(5, 24),
62+
Diagnostic().WithArguments("Bar").WithLocation(5, 14),
63+
Diagnostic().WithArguments("Par").WithLocation(5, 24),
6464
};
6565

66-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
67-
6866
var fixedCode = @"public class TypeName
6967
{
7068
public void MethodName()
@@ -73,8 +71,7 @@ public void MethodName()
7371
}
7472
}";
7573

76-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
77-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
74+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
7875
}
7976

8077
[Fact]
@@ -97,11 +94,8 @@ public void MethodName()
9794
}
9895
}";
9996

100-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("_bar").WithLocation(5, 37);
101-
102-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
103-
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
104-
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
97+
DiagnosticResult expected = Diagnostic().WithArguments("_bar").WithLocation(5, 37);
98+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
10599
}
106100

107101
[Fact]
@@ -136,11 +130,8 @@ public void MethodName()
136130
}
137131
}";
138132

139-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("ArgEx").WithLocation(10, 60);
140-
141-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
142-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
143-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
133+
DiagnosticResult expected = Diagnostic().WithArguments("ArgEx").WithLocation(10, 60);
134+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
144135
}
145136

146137
[Fact]
@@ -165,11 +156,8 @@ public void MethodName()
165156
}
166157
}";
167158

168-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("X").WithLocation(5, 23);
169-
170-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
171-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
172-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
159+
DiagnosticResult expected = Diagnostic().WithArguments("X").WithLocation(5, 23);
160+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
173161
}
174162

175163
[Fact]
@@ -200,11 +188,8 @@ public void MethodName()
200188
}
201189
}";
202190

203-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("X").WithLocation(7, 18);
204-
205-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
206-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
207-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
191+
DiagnosticResult expected = Diagnostic().WithArguments("X").WithLocation(7, 18);
192+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
208193
}
209194

210195
[Fact]
@@ -218,7 +203,7 @@ public void MethodName()
218203
}
219204
}";
220205

221-
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
206+
await VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
222207
}
223208

224209
[Fact]
@@ -233,9 +218,7 @@ public void MethodName()
233218
}
234219
}";
235220

236-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Variable").WithLocation(6, 51);
237-
238-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
221+
DiagnosticResult expected = Diagnostic().WithArguments("Variable").WithLocation(6, 51);
239222

240223
var fixedCode = @"public class TypeName
241224
{
@@ -246,8 +229,7 @@ public void MethodName()
246229
}
247230
}";
248231

249-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
250-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
232+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
251233
}
252234

253235
[Fact]
@@ -262,9 +244,7 @@ public void MethodName()
262244
}
263245
}";
264246

265-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Variable").WithLocation(6, 16);
266-
267-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
247+
DiagnosticResult expected = Diagnostic().WithArguments("Variable").WithLocation(6, 16);
268248

269249
var fixedCode = @"public class TypeName
270250
{
@@ -275,8 +255,7 @@ public void MethodName()
275255
}
276256
}";
277257

278-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
279-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
258+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
280259
}
281260

282261
[Fact]
@@ -290,9 +269,7 @@ public void MethodName()
290269
}
291270
}";
292271

293-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Int").WithLocation(5, 38);
294-
295-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
272+
DiagnosticResult expected = Diagnostic().WithArguments("Int").WithLocation(5, 38);
296273

297274
var fixedCode = @"public class TypeName
298275
{
@@ -302,8 +279,7 @@ public void MethodName()
302279
}
303280
}";
304281

305-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
306-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
282+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
307283
}
308284

309285
[Fact]
@@ -317,9 +293,7 @@ public void MethodName(int parameter)
317293
}
318294
}";
319295

320-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Parameter").WithLocation(5, 52);
321-
322-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
296+
DiagnosticResult expected = Diagnostic().WithArguments("Parameter").WithLocation(5, 52);
323297

324298
var fixedCode = @"public class TypeName
325299
{
@@ -329,8 +303,7 @@ public void MethodName(int parameter)
329303
}
330304
}";
331305

332-
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
333-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
306+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
334307
}
335308

336309
[Fact]
@@ -346,10 +319,8 @@ public void MethodName(int parameter)
346319
}
347320
}";
348321

349-
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("__").WithLocation(7, 52);
350-
351-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
352-
await this.VerifyCSharpFixAsync(testCode, testCode).ConfigureAwait(false);
322+
DiagnosticResult expected = Diagnostic().WithArguments("__").WithLocation(7, 52);
323+
await VerifyCSharpFixAsync(testCode, expected, testCode, CancellationToken.None).ConfigureAwait(false);
353324
}
354325
}
355326
}

0 commit comments

Comments
 (0)