@@ -317,6 +317,61 @@ public async Task TestPreprocessorDirectivesAsync()
317317 await this . VerifyCSharpFixAsync ( testCode , fixedTestCode ) . ConfigureAwait ( false ) ;
318318 }
319319
320+ /// <summary>
321+ /// This is a regression test for DotNetAnalyzers/StyleCopAnalyzers#1897.
322+ /// </summary>
323+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
324+ [ Fact ]
325+ public async Task TestInvalidOrderedUsingDirectivesInNamespaceDeclarationWithFileHeaderAsync ( )
326+ {
327+ var testCode = @"// <copyright file=""VoiceCommandService.cs"" company=""Foo Corporation"">
328+ // Copyright (c) FooCorporation. All rights reserved.
329+ // </copyright>
330+
331+ namespace Foo.Garage.XYZ
332+ {
333+ using System;
334+ using Newtonsoft.Json;
335+ using Foo.Garage.XYZ;
336+ }
337+
338+ namespace Newtonsoft.Json
339+ {
340+ }
341+ " ;
342+
343+ var fixedTestCode = @"// <copyright file=""VoiceCommandService.cs"" company=""Foo Corporation"">
344+ // Copyright (c) FooCorporation. All rights reserved.
345+ // </copyright>
346+
347+ // <copyright file=""VoiceCommandService.cs"" company=""Foo Corporation"">
348+ // Copyright (c) FooCorporation. All rights reserved.
349+ // </copyright>
350+
351+ namespace Foo.Garage.XYZ
352+ {
353+ using System;
354+ using Foo.Garage.XYZ;
355+ using Newtonsoft.Json;
356+ }
357+
358+ namespace Newtonsoft.Json
359+ {
360+ }
361+ " ;
362+
363+ DiagnosticResult [ ] expected =
364+ {
365+ this . CSharpDiagnostic ( ) . WithLocation ( 8 , 5 ) ,
366+ this . CSharpDiagnostic ( ) . WithLocation ( 8 , 5 ) ,
367+ this . CSharpDiagnostic ( ) . WithLocation ( 8 , 5 ) ,
368+ } ;
369+
370+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
371+ await this . VerifyCSharpDiagnosticAsync ( fixedTestCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
372+ await this . VerifyCSharpFixAsync ( testCode , fixedTestCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
373+ }
374+
320375 /// <inheritdoc/>
321376 protected override IEnumerable < string > GetDisabledDiagnostics ( )
322377 {
0 commit comments