Skip to content

Commit 4170c61

Browse files
committed
Use multi-file overload for VerifyCSharpDiagnosticAsync.
1 parent b8a422b commit 4170c61

1 file changed

Lines changed: 34 additions & 36 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public async Task TestOneElementAsync()
2121
var testCode = @"%1 Foo
2222
{
2323
}";
24-
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
24+
25+
testCode = testCode.Replace("%1", this.Keyword);
26+
27+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
2528
}
2629

2730
[Fact]
@@ -45,18 +48,17 @@ public async Task TestTwoElementsAsync()
4548
}"
4649
};
4750

51+
testCode = testCode.Replace("%1", this.Keyword);
52+
fixedCode = fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray();
53+
4854
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2);
4955

50-
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), expected, CancellationToken.None).ConfigureAwait(false);
51-
52-
foreach (var code in fixedCode)
53-
{
54-
await this.VerifyCSharpDiagnosticAsync(code.Replace("%1", this.Keyword), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
55-
}
56+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
57+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
5658

5759
if (this.SupportsCodeFix)
5860
{
59-
await this.VerifyCSharpFixAsync(new[] { testCode.Replace("%1", this.Keyword) }, fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray(), cancellationToken: CancellationToken.None).ConfigureAwait(false);
61+
await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
6062
}
6163
}
6264

@@ -88,22 +90,21 @@ public async Task TestThreeElementsAsync()
8890
}"
8991
};
9092

93+
testCode = testCode.Replace("%1", this.Keyword);
94+
fixedCode = fixedCode.Select(code => code.Replace("%1", this.Keyword)).ToArray();
95+
9196
DiagnosticResult[] expected =
9297
{
9398
this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2),
9499
this.CSharpDiagnostic().WithLocation(7, this.Keyword.Length + 2)
95100
};
96101

97-
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), expected, CancellationToken.None).ConfigureAwait(false);
98-
99-
foreach (var code in fixedCode)
100-
{
101-
await this.VerifyCSharpDiagnosticAsync(code.Replace("%1", this.Keyword), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
102-
}
102+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
103+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
103104

104105
if (this.SupportsCodeFix)
105106
{
106-
await this.VerifyCSharpFixAsync(new[] { testCode.Replace("%1", this.Keyword) }, fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray(), cancellationToken: CancellationToken.None).ConfigureAwait(false);
107+
await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
107108
}
108109
}
109110

@@ -132,18 +133,17 @@ public async Task TestRemoveWarningSuppressionAsync()
132133
}"
133134
};
134135

135-
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2);
136+
testCode = testCode.Replace("%1", this.Keyword);
137+
fixedCode = fixedCode.Select(code => code.Replace("%1", this.Keyword)).ToArray();
136138

137-
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), expected, CancellationToken.None).ConfigureAwait(false);
139+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2);
138140

139-
foreach (var code in fixedCode)
140-
{
141-
await this.VerifyCSharpDiagnosticAsync(code.Replace("%1", this.Keyword), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
142-
}
141+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
142+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
143143

144144
if (this.SupportsCodeFix)
145145
{
146-
await this.VerifyCSharpFixAsync(new[] { testCode.Replace("%1", this.Keyword) }, fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray(), cancellationToken: CancellationToken.None).ConfigureAwait(false);
146+
await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
147147
}
148148
}
149149

@@ -211,18 +211,17 @@ public async Task TestRemovePreprocessorDirectivesAsync()
211211
}"
212212
};
213213

214+
testCode = testCode.Replace("%1", this.Keyword);
215+
fixedCode = fixedCode.Select(code => code.Replace("%1", this.Keyword)).ToArray();
216+
214217
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2);
215218

216-
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), expected, CancellationToken.None).ConfigureAwait(false);
217-
218-
foreach (var code in fixedCode)
219-
{
220-
await this.VerifyCSharpDiagnosticAsync(code.Replace("%1", this.Keyword), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
221-
}
219+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
220+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
222221

223222
if (this.SupportsCodeFix)
224223
{
225-
await this.VerifyCSharpFixAsync(new[] { testCode.Replace("%1", this.Keyword) }, fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray(), cancellationToken: CancellationToken.None).ConfigureAwait(false);
224+
await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
226225
}
227226
}
228227

@@ -256,18 +255,17 @@ public async Task TestPreservePreprocessorDirectivesAsync()
256255
}"
257256
};
258257

259-
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, this.Keyword.Length + 2);
258+
testCode = testCode.Replace("%1", this.Keyword);
259+
fixedCode = fixedCode.Select(code => code.Replace("%1", this.Keyword)).ToArray();
260260

261-
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), expected, CancellationToken.None).ConfigureAwait(false);
261+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, this.Keyword.Length + 2);
262262

263-
foreach (var code in fixedCode)
264-
{
265-
await this.VerifyCSharpDiagnosticAsync(code.Replace("%1", this.Keyword), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
266-
}
263+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
264+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
267265

268266
if (this.SupportsCodeFix)
269267
{
270-
await this.VerifyCSharpFixAsync(new[] { testCode.Replace("%1", this.Keyword) }, fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray(), cancellationToken: CancellationToken.None).ConfigureAwait(false);
268+
await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
271269
}
272270
}
273271
}

0 commit comments

Comments
 (0)