Skip to content

Commit f471f87

Browse files
committed
added test for file header decoration
1 parent 8880025 commit f471f87

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1633UnitTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,24 @@ public class SA1633UnitTests : FileHeaderTestBase
2424
}
2525
}
2626
}
27+
";
28+
29+
private const string DecoratedXmlMultiLineHeaderTestSettings = @"
30+
{
31+
""settings"": {
32+
""documentationRules"": {
33+
""companyName"": ""FooCorp"",
34+
""copyrightText"": "" Copyright (c) {companyName}. All rights reserved."",
35+
""headerDecoration"": ""-----------------------------------------------------------------------"",
36+
}
37+
}
38+
}
2739
";
2840

2941
private bool useNoXmlSettings;
3042

43+
private bool useDecoratedXmlMultiLineHeaderTestSettings;
44+
3145
/// <summary>
3246
/// Verifies that the analyzer will report <see cref="FileHeaderAnalyzers.SA1633DescriptorMissing"/> for
3347
/// projects using XML headers (the default) when the file is completely missing a header.
@@ -167,6 +181,36 @@ namespace Foo
167181
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
168182
}
169183

184+
/// <summary>
185+
/// Verifies that a file without a header, but with leading trivia will produce the correct diagnostic message.
186+
/// </summary>
187+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
188+
[Fact]
189+
public async Task TestMissingFileHeaderWithDecorationAsync()
190+
{
191+
var testCode = @"namespace Foo
192+
{
193+
}
194+
";
195+
var fixedCode = @"// -----------------------------------------------------------------------
196+
// <copyright file=""Test0.cs"" company=""FooCorp"">
197+
// Copyright (c) FooCorp. All rights reserved.
198+
// </copyright>
199+
// -----------------------------------------------------------------------
200+
201+
namespace Foo
202+
{
203+
}
204+
";
205+
206+
this.useDecoratedXmlMultiLineHeaderTestSettings = true;
207+
208+
var expectedDiagnostic = this.CSharpDiagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1);
209+
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None).ConfigureAwait(false);
210+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
211+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
212+
}
213+
170214
/// <summary>
171215
/// Verifies that a file header without XML structure will produce the correct diagnostic message.
172216
/// </summary>
@@ -308,6 +352,11 @@ protected override string GetSettings()
308352
return NoXmlMultiLineHeaderTestSettings;
309353
}
310354

355+
if (this.useDecoratedXmlMultiLineHeaderTestSettings)
356+
{
357+
return DecoratedXmlMultiLineHeaderTestSettings;
358+
}
359+
311360
return base.GetSettings();
312361
}
313362

0 commit comments

Comments
 (0)