@@ -477,6 +477,98 @@ public async Task VerifyCodefixForElsePartOfDirectiveTriviaAsync()
477477 await this . VerifyCSharpFixAsync ( testCode , fixedTestCode ) . ConfigureAwait ( false ) ;
478478 }
479479
480+ /// <summary>
481+ /// Verifies that the code fix will handle using statements with directive trivia outside of namespaces
482+ /// This is a regression test for #1733
483+ /// </summary>
484+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
485+ [ Fact ]
486+ public async Task VerifyCodefixForDirectiveTriviaOutsideOfNamespacesAsync ( )
487+ {
488+ var testCode = @"// <copyright file=""Program.cs"" company=""PlaceholderCompany"" >
489+ // Copyright (c) PlaceholderCompany. All rights reserved.
490+ // </copyright>
491+
492+ #if DEBUG
493+ using Fish;
494+ #else
495+ using Fish.Face;
496+ #endif
497+ using System.Text;
498+ using System;
499+
500+ namespace StyleCopBugRepro
501+ {
502+ class Program
503+ {
504+ static void Main(string[] args)
505+ {
506+ Int32 q;
507+ Haddock h;
508+ StringBuilder sb;
509+ }
510+ }
511+ }
512+
513+ namespace Fish
514+ {
515+ public class Haddock { }
516+
517+ namespace Face
518+ {
519+ public class Haddock { }
520+ }
521+ }
522+ " ;
523+
524+ var fixedTestCode = @"// <copyright file=""Program.cs"" company=""PlaceholderCompany"" >
525+ // Copyright (c) PlaceholderCompany. All rights reserved.
526+ // </copyright>
527+
528+ #if DEBUG
529+ using Fish;
530+ #else
531+ using Fish.Face;
532+ #endif
533+ using System;
534+ using System.Text;
535+
536+ namespace StyleCopBugRepro
537+ {
538+ class Program
539+ {
540+ static void Main(string[] args)
541+ {
542+ Int32 q;
543+ Haddock h;
544+ StringBuilder sb;
545+ }
546+ }
547+ }
548+
549+ namespace Fish
550+ {
551+ public class Haddock { }
552+
553+ namespace Face
554+ {
555+ public class Haddock { }
556+ }
557+ }
558+ " ;
559+
560+ DiagnosticResult [ ] expected =
561+ {
562+ this . CSharpDiagnostic ( SA1200UsingDirectivesMustBePlacedWithinNamespace . DiagnosticId ) . WithLocation ( 8 , 1 ) ,
563+ this . CSharpDiagnostic ( SA1200UsingDirectivesMustBePlacedWithinNamespace . DiagnosticId ) . WithLocation ( 10 , 1 ) ,
564+ this . CSharpDiagnostic ( SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace . DiagnosticId ) . WithLocation ( 10 , 1 ) ,
565+ this . CSharpDiagnostic ( SA1200UsingDirectivesMustBePlacedWithinNamespace . DiagnosticId ) . WithLocation ( 11 , 1 )
566+ } ;
567+
568+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
569+ await this . VerifyCSharpFixAsync ( testCode , fixedTestCode ) . ConfigureAwait ( false ) ;
570+ }
571+
480572 /// <inheritdoc/>
481573 protected override IEnumerable < string > GetDisabledDiagnostics ( )
482574 {
0 commit comments