From fc85afda068297f82bfa91635d9aaf9b4a119b60 Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Tue, 4 Oct 2016 15:32:34 -0700 Subject: [PATCH] added unit test --- ...eviewSolutionCrawlerRegistrationService.cs | 2 +- .../SolutionCrawler/WorkCoordinatorTests.cs | 39 +++++++++++++++++-- .../SolutionCrawlerRegistrationService.cs | 2 +- .../ISolutionCrawlerRegistrationService.cs | 2 +- ...NullSolutionCrawlerRegisterationService.cs | 2 +- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/EditorFeatures/Core/Shared/Preview/PreviewSolutionCrawlerRegistrationService.cs b/src/EditorFeatures/Core/Shared/Preview/PreviewSolutionCrawlerRegistrationService.cs index adafdf34e09..857840762c0 100644 --- a/src/EditorFeatures/Core/Shared/Preview/PreviewSolutionCrawlerRegistrationService.cs +++ b/src/EditorFeatures/Core/Shared/Preview/PreviewSolutionCrawlerRegistrationService.cs @@ -109,7 +109,7 @@ public async void Unregister(Workspace workspace, bool blockingShutdown = false) _owner._analyzerService.ShutdownAnalyzerFrom(_workspace); } - public void RegisterIncrementalAnalyzerProvider(IIncrementalAnalyzerProvider provider, IncrementalAnalyzerProviderMetadata metadata) + public void AddAnalyzerProvider(IIncrementalAnalyzerProvider provider, IncrementalAnalyzerProviderMetadata metadata) { // preview solution crawler doesn't support adding and removing analyzer dynamically throw new NotSupportedException(); diff --git a/src/EditorFeatures/Test/SolutionCrawler/WorkCoordinatorTests.cs b/src/EditorFeatures/Test/SolutionCrawler/WorkCoordinatorTests.cs index c1945fc2bd1..ad0e54c196d 100644 --- a/src/EditorFeatures/Test/SolutionCrawler/WorkCoordinatorTests.cs +++ b/src/EditorFeatures/Test/SolutionCrawler/WorkCoordinatorTests.cs @@ -42,6 +42,37 @@ public async Task RegisterService() } } + [Fact] + public async Task DynamicallyAddAnalyzer() + { + using (var workspace = new WorkCoordinatorWorkspace(SolutionCrawler)) + { + // create solution and wait for it to settle + var solution = GetInitialSolutionInfo(workspace); + workspace.OnSolutionAdded(solution); + await WaitWaiterAsync(workspace.ExportProvider); + + // create solution crawler and add new analyzer provider dynamically + var service = new SolutionCrawlerRegistrationService( + SpecializedCollections.EmptyEnumerable>(), + GetListeners(workspace.ExportProvider)); + + service.Register(workspace); + + var provider = new AnalyzerProvider(new Analyzer()); + service.AddAnalyzerProvider(provider, Metadata.Crawler); + + // wait for everything to settle + await WaitAsync(service, workspace); + + service.Unregister(workspace); + + // check whether everything ran as expected + Assert.Equal(10, provider.Analyzer.SyntaxDocumentIds.Count); + Assert.Equal(10, provider.Analyzer.DocumentIds.Count); + } + } + [Fact, WorkItem(747226, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/747226")] public async Task SolutionAdded_Simple() { @@ -997,23 +1028,23 @@ protected override void Dispose(bool finalize) private class AnalyzerProvider : IIncrementalAnalyzerProvider { - private readonly Analyzer _analyzer; + public readonly Analyzer Analyzer; public AnalyzerProvider(Analyzer analyzer) { - _analyzer = analyzer; + Analyzer = analyzer; } public IIncrementalAnalyzer CreateIncrementalAnalyzer(Workspace workspace) { - return _analyzer; + return Analyzer; } } internal class Metadata : IncrementalAnalyzerProviderMetadata { public Metadata(params string[] workspaceKinds) - : base(new Dictionary { { "WorkspaceKinds", workspaceKinds }, { "HighPriorityForActiveFile", false } }) + : base(new Dictionary { { "WorkspaceKinds", workspaceKinds }, { "HighPriorityForActiveFile", false }, { "Name", "TestAnalyzer" } }) { } diff --git a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs index 382349db6db..2ad2be3b84c 100644 --- a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs +++ b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs @@ -85,7 +85,7 @@ public void Unregister(Workspace workspace, bool blockingShutdown = false) SolutionCrawlerLogger.LogUnregistration(coordinator.CorrelationId); } - public void RegisterIncrementalAnalyzerProvider(IIncrementalAnalyzerProvider provider, IncrementalAnalyzerProviderMetadata metadata) + public void AddAnalyzerProvider(IIncrementalAnalyzerProvider provider, IncrementalAnalyzerProviderMetadata metadata) { // now update all existing work coordinator lock (_gate) diff --git a/src/Workspaces/Core/Portable/SolutionCrawler/ISolutionCrawlerRegistrationService.cs b/src/Workspaces/Core/Portable/SolutionCrawler/ISolutionCrawlerRegistrationService.cs index 06512a4e249..f9c68cacd4a 100644 --- a/src/Workspaces/Core/Portable/SolutionCrawler/ISolutionCrawlerRegistrationService.cs +++ b/src/Workspaces/Core/Portable/SolutionCrawler/ISolutionCrawlerRegistrationService.cs @@ -12,6 +12,6 @@ internal interface ISolutionCrawlerRegistrationService : IWorkspaceService void Register(Workspace workspace); void Unregister(Workspace workspace, bool blockingShutdown = false); - void RegisterIncrementalAnalyzerProvider(IIncrementalAnalyzerProvider provider, IncrementalAnalyzerProviderMetadata metadata); + void AddAnalyzerProvider(IIncrementalAnalyzerProvider provider, IncrementalAnalyzerProviderMetadata metadata); } } diff --git a/src/Workspaces/Core/Portable/SolutionCrawler/NullSolutionCrawlerRegisterationService.cs b/src/Workspaces/Core/Portable/SolutionCrawler/NullSolutionCrawlerRegisterationService.cs index af5a1801900..18bf7e69f9e 100644 --- a/src/Workspaces/Core/Portable/SolutionCrawler/NullSolutionCrawlerRegisterationService.cs +++ b/src/Workspaces/Core/Portable/SolutionCrawler/NullSolutionCrawlerRegisterationService.cs @@ -23,7 +23,7 @@ public void Unregister(Workspace workspace, bool blockingShutdown = false) // base implementation do nothing. } - public void RegisterIncrementalAnalyzerProvider(IIncrementalAnalyzerProvider provider, IncrementalAnalyzerProviderMetadata metadata) + public void AddAnalyzerProvider(IIncrementalAnalyzerProvider provider, IncrementalAnalyzerProviderMetadata metadata) { // base implementation do nothing. } -- GitLab