22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5- #nullable disable
6-
75using System . Diagnostics . CodeAnalysis ;
86using System . Linq ;
97using System . Threading . Tasks ;
8+ using Microsoft . CodeAnalysis . AddImport ;
109using Microsoft . CodeAnalysis . CodeRefactorings ;
10+ using Microsoft . CodeAnalysis . CodeStyle ;
1111using Microsoft . CodeAnalysis . CSharp . CodeRefactorings . AddMissingImports ;
12+ using Microsoft . CodeAnalysis . CSharp . CodeStyle ;
1213using Microsoft . CodeAnalysis . Editing ;
1314using Microsoft . CodeAnalysis . Editor . CSharp . UnitTests . CodeRefactorings ;
1415using Microsoft . CodeAnalysis . Editor . UnitTests . CodeActions ;
@@ -26,6 +27,12 @@ public sealed class CSharpAddMissingImportsRefactoringProviderTests : AbstractCS
2627 protected override CodeRefactoringProvider CreateCodeRefactoringProvider ( EditorTestWorkspace workspace , TestParameters parameters )
2728 => new CSharpAddMissingImportsRefactoringProvider ( ) ;
2829
30+ private static readonly CodeStyleOption2 < AddImportPlacement > InsideNamespaceOption =
31+ new ( AddImportPlacement . InsideNamespace , NotificationOption2 . Error ) ;
32+
33+ private static readonly CodeStyleOption2 < AddImportPlacement > OutsideNamespaceOption =
34+ new ( AddImportPlacement . InsideNamespace , NotificationOption2 . Error ) ;
35+
2936 protected override void InitializeWorkspace ( EditorTestWorkspace workspace , TestParameters parameters )
3037 {
3138 // Treat the span being tested as the pasted span
@@ -46,13 +53,16 @@ protected override void InitializeWorkspace(EditorTestWorkspace workspace, TestP
4653 private Task TestInRegularAndScriptAsync (
4754 [ StringSyntax ( PredefinedEmbeddedLanguageNames . CSharpTest ) ] string initialMarkup ,
4855 [ StringSyntax ( PredefinedEmbeddedLanguageNames . CSharpTest ) ] string expectedMarkup ,
49- bool placeSystemNamespaceFirst , bool separateImportDirectiveGroups )
56+ bool placeSystemNamespaceFirst ,
57+ bool separateImportDirectiveGroups ,
58+ bool placeInsideNamespace = false )
5059 {
5160 var options =
5261 new OptionsCollection ( GetLanguage ( ) )
5362 {
5463 { GenerationOptions . PlaceSystemNamespaceFirst , placeSystemNamespaceFirst } ,
5564 { GenerationOptions . SeparateImportDirectiveGroups , separateImportDirectiveGroups } ,
65+ { CSharpCodeStyleOptions . PreferredUsingDirectivePlacement , placeInsideNamespace ? InsideNamespaceOption : OutsideNamespaceOption } ,
5666 } ;
5767 return TestInRegularAndScriptAsync ( initialMarkup , expectedMarkup , options : options ) ;
5868 }
@@ -353,4 +363,29 @@ class C
353363 List<Type> list;
354364 }
355365 """ , placeSystemNamespaceFirst : true , separateImportDirectiveGroups : true ) ;
366+
367+ [ WpfTheory , CombinatorialData , WorkItem ( "https://github.com/dotnet/roslyn/issues/54842" ) ]
368+ public Task TestWithNamespace ( bool placeInsideNamespace )
369+ => TestInRegularAndScriptAsync ( """
370+ namespace N
371+ {
372+ using System;
373+
374+ class C
375+ {
376+ [|List<Type> list;|]
377+ }
378+ }
379+ """ , """
380+ namespace N
381+ {
382+ using System;
383+ using System.Collections.Generic;
384+
385+ class C
386+ {
387+ List<Type> list;
388+ }
389+ }
390+ """ , placeSystemNamespaceFirst : true , separateImportDirectiveGroups : true , placeInsideNamespace ) ;
356391}
0 commit comments