Skip to content

Commit 4b01343

Browse files
committed
Use CreateWorkspaceAsync from the testing library
1 parent 83549ef commit 4b01343

File tree

6 files changed

+10
-27
lines changed

6 files changed

+10
-27
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/Lightup/IImportScopeWrapperCSharp11UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class TestClass
5252
}
5353
";
5454

55-
var workspace = GenericAnalyzerTest.CreateWorkspace();
55+
var workspace = await GenericAnalyzerTest.CreateWorkspaceAsync().ConfigureAwait(false);
5656
var projectId = ProjectId.CreateNewId();
5757

5858
var references = await GenericAnalyzerTest.ReferenceAssemblies

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Settings/SettingsCSharp8UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private async Task<SyntaxTreeAnalysisContext> CreateAnalysisContextFromEditorCon
206206
var documentId = DocumentId.CreateNewId(projectId);
207207
var analyzerConfigDocumentId = DocumentId.CreateNewId(projectId);
208208

209-
var solution = GenericAnalyzerTest.CreateWorkspace()
209+
var solution = (await GenericAnalyzerTest.CreateWorkspaceAsync().ConfigureAwait(false))
210210
.CurrentSolution
211211
.AddProject(projectId, TestProjectName, TestProjectName, LanguageNames.CSharp)
212212
.AddDocument(documentId, "/0/Test0.cs", SourceText.From(string.Empty))

StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/IndentationHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public async Task VerifyGetIndentationStepsForTokenNotAtStartOfLineAsync()
142142

143143
private static async Task<Document> CreateTestDocumentAsync(string source, int indentationSize = 4, bool useTabs = false, int tabSize = 4, CancellationToken cancellationToken = default)
144144
{
145-
var workspace = GenericAnalyzerTest.CreateWorkspace();
145+
var workspace = await GenericAnalyzerTest.CreateWorkspaceAsync().ConfigureAwait(false);
146146
workspace.Options = workspace.Options
147147
.WithChangedOption(FormattingOptions.IndentationSize, LanguageNames.CSharp, indentationSize)
148148
.WithChangedOption(FormattingOptions.UseTabs, LanguageNames.CSharp, useTabs)

StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SymbolNameHelpersUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private static Document GetDocument(Solution solution, string sourceCode)
108108

109109
private static async Task<Solution> CreateTestSolutionAsync(CSharpCompilationOptions compilationOptions)
110110
{
111-
var workspace = GenericAnalyzerTest.CreateWorkspace();
111+
var workspace = await GenericAnalyzerTest.CreateWorkspaceAsync().ConfigureAwait(false);
112112
var projectId = ProjectId.CreateNewId();
113113

114114
var references = await GenericAnalyzerTest.ReferenceAssemblies

StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ private static async Task<SyntaxTreeAnalysisContext> CreateAnalysisContextAsync(
431431
var projectId = ProjectId.CreateNewId();
432432
var documentId = DocumentId.CreateNewId(projectId);
433433

434-
var solution = GenericAnalyzerTest.CreateWorkspace()
434+
var solution = (await GenericAnalyzerTest.CreateWorkspaceAsync().ConfigureAwait(false))
435435
.CurrentSolution
436436
.AddProject(projectId, TestProjectName, TestProjectName, LanguageNames.CSharp)
437437
.AddDocument(documentId, "Test0.cs", SourceText.From(string.Empty));

StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/GenericAnalyzerTest.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ namespace StyleCop.Analyzers.Test.Verifiers
55
{
66
using System;
77
using System.Collections.Immutable;
8-
using System.Threading;
98
using System.Threading.Tasks;
109
using Microsoft.CodeAnalysis;
11-
using Microsoft.CodeAnalysis.Host.Mef;
10+
using Microsoft.CodeAnalysis.CSharp.Testing;
1211
using Microsoft.CodeAnalysis.Testing;
13-
using Microsoft.VisualStudio.Composition;
1412
using StyleCop.Analyzers.Lightup;
1513

1614
internal static class GenericAnalyzerTest
1715
{
1816
internal static readonly ReferenceAssemblies ReferenceAssemblies;
19-
20-
private static readonly Lazy<IExportProviderFactory> ExportProviderFactory;
17+
private static readonly AnalyzerTest<DefaultVerifier> WorkspaceHelper =
18+
new CSharpCodeFixTest<EmptyDiagnosticAnalyzer, EmptyCodeFixProvider, DefaultVerifier>();
2119

2220
static GenericAnalyzerTest()
2321
{
@@ -62,26 +60,11 @@ static GenericAnalyzerTest()
6260
ReferenceAssemblies = defaultReferenceAssemblies.AddPackages(ImmutableArray.Create(
6361
new PackageIdentity("Microsoft.CodeAnalysis.CSharp", codeAnalysisTestVersion),
6462
new PackageIdentity("System.ValueTuple", "4.5.0")));
65-
66-
ExportProviderFactory = new Lazy<IExportProviderFactory>(
67-
() =>
68-
{
69-
var discovery = new AttributedPartDiscovery(Resolver.DefaultInstance, isNonPublicSupported: true);
70-
var parts = Task.Run(() => discovery.CreatePartsAsync(MefHostServices.DefaultAssemblies)).GetAwaiter().GetResult();
71-
var catalog = ComposableCatalog.Create(Resolver.DefaultInstance).AddParts(parts);
72-
73-
var configuration = CompositionConfiguration.Create(catalog);
74-
var runtimeComposition = RuntimeComposition.CreateRuntimeComposition(configuration);
75-
return runtimeComposition.CreateExportProviderFactory();
76-
},
77-
LazyThreadSafetyMode.ExecutionAndPublication);
7863
}
7964

80-
internal static AdhocWorkspace CreateWorkspace()
65+
internal static async Task<Workspace> CreateWorkspaceAsync()
8166
{
82-
var exportProvider = ExportProviderFactory.Value.CreateExportProvider();
83-
var host = MefV1HostServices.Create(exportProvider.AsExportProvider());
84-
return new AdhocWorkspace(host);
67+
return await WorkspaceHelper.CreateWorkspaceAsync().ConfigureAwait(false);
8568
}
8669
}
8770
}

0 commit comments

Comments
 (0)