Skip to content

Commit ed512f9

Browse files
committed
Use string interpolation to improve test readability
1 parent 297485d commit ed512f9

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,44 +1138,44 @@ private async Task TestConstructorCorrectDocumentationCustomizedAsync(string typ
11381138

11391139
private async Task TestConstructorMissingDocumentationAsync(string typeKind, string modifiers, string part1, string part2, bool generic)
11401140
{
1141-
var testCode = @"namespace FooNamespace
1141+
string typeParameters = generic ? "<T1, T2>" : string.Empty;
1142+
string arguments = typeKind == "struct" && modifiers != "static" ? "int argument" : null;
1143+
var testCode = $@"namespace FooNamespace
11421144
{{
1143-
public {0} Foo{1}
1145+
public {typeKind} Foo{typeParameters}
11441146
{{
11451147
/// <summary>
11461148
/// </summary>
1147-
{2}
1148-
Foo({3})
1149+
{modifiers}
1150+
Foo({arguments})
11491151
{{
11501152
11511153
}}
11521154
}}
11531155
}}";
1154-
string arguments = typeKind == "struct" && modifiers != "static" ? "int argument" : null;
1155-
testCode = string.Format(testCode, typeKind, generic ? "<T1, T2>" : string.Empty, modifiers, arguments);
1156-
1157-
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 13);
1158-
1159-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
11601156

1161-
var fixedCode = @"namespace FooNamespace
1157+
string crefTypeParameters = generic ? "{T1, T2}" : string.Empty;
1158+
string part3 = part2.EndsWith(".") ? string.Empty : ".";
1159+
var fixedCode = $@"namespace FooNamespace
11621160
{{
1163-
public {0} Foo{1}
1161+
public {typeKind} Foo{typeParameters}
11641162
{{
11651163
/// <summary>
1166-
/// {3}<see cref=""Foo{2}""/>{4}{5}
1164+
/// {part1}<see cref=""Foo{crefTypeParameters}""/>{part2}{part3}
11671165
/// </summary>
1168-
{6}
1169-
Foo({7})
1166+
{modifiers}
1167+
Foo({arguments})
11701168
{{
11711169
11721170
}}
11731171
}}
11741172
}}";
11751173

1176-
string part3 = part2.EndsWith(".") ? string.Empty : ".";
1177-
fixedCode = string.Format(fixedCode, typeKind, generic ? "<T1, T2>" : string.Empty, generic ? "{T1, T2}" : string.Empty, part1, part2, part3, modifiers, arguments);
1178-
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
1174+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 13);
1175+
1176+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1177+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
1178+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
11791179
}
11801180

11811181
private async Task TestConstructorSimpleDocumentationAsync(string typeKind, string modifiers, string part1, string part2, bool generic)

0 commit comments

Comments
 (0)