@@ -14,6 +14,20 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1414 /// </summary>
1515 public class SA1638UnitTests : FileHeaderTestBase
1616 {
17+ private const string DecoratedXmlMultiLineHeaderTestSettings = @"
18+ {
19+ ""settings"": {
20+ ""documentationRules"": {
21+ ""companyName"": ""FooCorp"",
22+ ""copyrightText"": "" Copyright (c) {companyName}. All rights reserved."",
23+ ""headerDecoration"": ""-----------------------------------------------------------------------"",
24+ }
25+ }
26+ }
27+ " ;
28+
29+ private bool useDecoratedXmlMultiLineHeaderTestSettings ;
30+
1731 /// <summary>
1832 /// Verifies that a file header with a mismatching file attribute in the copyright element will produce the expected diagnostic message.
1933 /// </summary>
@@ -44,9 +58,56 @@ namespace Bar
4458 await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
4559 }
4660
61+ /// <summary>
62+ /// Verifies that a file header with a mismatching file attribute in the copyright element will produce the expected diagnostic message.
63+ /// </summary>
64+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
65+ [ Fact ]
66+ public async Task TestCopyrightElementWithMismatchingFileAttributeAndDecorationAsync ( )
67+ {
68+ var testCode = @"// -----------------------------------------------------------------------
69+ // <copyright file=""wrongfile.cs"" company=""FooCorp"">
70+ // Copyright (c) FooCorp. All rights reserved.
71+ // </copyright>
72+ // -----------------------------------------------------------------------
73+
74+ namespace Bar
75+ {
76+ }
77+ " ;
78+ var fixedCode = @"// -----------------------------------------------------------------------
79+ // <copyright file=""Test0.cs"" company=""FooCorp"">
80+ // Copyright (c) FooCorp. All rights reserved.
81+ // </copyright>
82+ // -----------------------------------------------------------------------
83+
84+ namespace Bar
85+ {
86+ }
87+ " ;
88+
89+ this . useDecoratedXmlMultiLineHeaderTestSettings = true ;
90+
91+ var expectedDiagnostic = this . CSharpDiagnostic ( FileHeaderAnalyzers . SA1638Descriptor ) . WithLocation ( 2 , 4 ) ;
92+ await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None ) . ConfigureAwait ( false ) ;
93+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
94+ await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
95+ }
96+
4797 protected override CodeFixProvider GetCSharpCodeFixProvider ( )
4898 {
4999 return new FileHeaderCodeFixProvider ( ) ;
50100 }
101+
102+ /// <inheritdoc/>
103+ protected override string GetSettings ( )
104+ {
105+ if ( this . useDecoratedXmlMultiLineHeaderTestSettings )
106+ {
107+ return DecoratedXmlMultiLineHeaderTestSettings ;
108+ }
109+
110+ return base . GetSettings ( ) ;
111+ }
51112 }
52113}
0 commit comments