Skip to content

Commit 3e2cadf

Browse files
Add test showing issue no longer reproes (#79368)
2 parents 50038ad + dad51bf commit 3e2cadf

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/EditorFeatures/CSharpTest/AddMissingImports/CSharpAddMissingImportsRefactoringProviderTests.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
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-
75
using System.Diagnostics.CodeAnalysis;
86
using System.Linq;
97
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.AddImport;
109
using Microsoft.CodeAnalysis.CodeRefactorings;
10+
using Microsoft.CodeAnalysis.CodeStyle;
1111
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.AddMissingImports;
12+
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
1213
using Microsoft.CodeAnalysis.Editing;
1314
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
1415
using 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
}

src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@
1414
namespace Roslyn.VisualStudio.NewIntegrationTests.CSharp;
1515

1616
[Trait(Traits.Feature, Traits.Features.AddMissingImports)]
17-
public class CSharpAddMissingUsingsOnPaste : AbstractEditorTest
17+
public sealed class CSharpAddMissingUsingsOnPaste() : AbstractEditorTest(nameof(CSharpAddMissingUsingsOnPaste))
1818
{
19-
public CSharpAddMissingUsingsOnPaste()
20-
: base(nameof(CSharpAddMissingUsingsOnPaste))
21-
{
22-
}
23-
2419
protected override string LanguageName => LanguageNames.CSharp;
2520

2621
[IdeFact]

0 commit comments

Comments
 (0)