private async Task TestWithOptionsAsync(TestWorkspace workspace, params Action<object>[] expectedResults) { var testDocument = workspace.DocumentWithCursor; var position = testDocument.CursorPosition.GetValueOrDefault(); var documentId = workspace.GetDocumentId(testDocument); var document = workspace.CurrentSolution.GetDocument(documentId); var provider = new SemanticQuickInfoProvider( workspace.GetService<IProjectionBufferFactoryService>(), workspace.GetService<IEditorOptionsFactoryService>(), workspace.GetService<ITextEditorFactoryService>(), workspace.GetService<IGlyphService>(), workspace.GetService<ClassificationTypeMap>()); await TestWithOptionsAsync(document, provider, position, expectedResults); // speculative semantic model if (await CanUseSpeculativeSemanticModelAsync(document, position)) { var buffer = testDocument.TextBuffer; using (var edit = buffer.CreateEdit()) { var currentSnapshot = buffer.CurrentSnapshot; edit.Replace(0, currentSnapshot.Length, currentSnapshot.GetText()); edit.Apply(); } await TestWithOptionsAsync(document, provider, position, expectedResults); } }
private async void AssertResetInteractive( TestWorkspace workspace, Project project, bool buildSucceeds, List<string> expectedReferences = null, List<string> expectedUsings = null) { expectedReferences = expectedReferences ?? new List<string>(); expectedUsings = expectedUsings ?? new List<string>(); InteractiveWindowTestHost testHost = new InteractiveWindowTestHost(); List<string> executedSubmissionCalls = new List<string>(); EventHandler<string> ExecuteSubmission = (_, code) => { executedSubmissionCalls.Add(code); }; testHost.Evaluator.OnExecute += ExecuteSubmission; IWaitIndicator waitIndicator = workspace.GetService<IWaitIndicator>(); IEditorOptionsFactoryService editorOptionsFactoryService = workspace.GetService<IEditorOptionsFactoryService>(); var editorOptions = editorOptionsFactoryService.GetOptions(testHost.Window.CurrentLanguageBuffer); var newLineCharacter = editorOptions.GetNewLineCharacter(); TestResetInteractive resetInteractive = new TestResetInteractive( waitIndicator, editorOptionsFactoryService, CreateReplReferenceCommand, CreateImport, buildSucceeds: buildSucceeds) { References = ImmutableArray.CreateRange(GetProjectReferences(workspace, project)), ReferenceSearchPaths = ImmutableArray.Create("rsp1", "rsp2"), SourceSearchPaths = ImmutableArray.Create("ssp1", "ssp2"), ProjectNamespaces = ImmutableArray.Create("System", "ResetInteractiveTestsDocument", "VisualBasicResetInteractiveTestsDocument"), NamespacesToImport = ImmutableArray.Create("System", "ResetInteractiveTestsDocument"), ProjectDirectory = "pj", }; await resetInteractive.Execute(testHost.Window, "Interactive C#"); // Validate that the project was rebuilt. Assert.Equal(1, resetInteractive.BuildProjectCount); Assert.Equal(0, resetInteractive.CancelBuildProjectCount); var expectedSubmissions = new List<string>(); if (expectedReferences.Any()) { expectedSubmissions.AddRange(expectedReferences.Select(r => r + newLineCharacter)); } if (expectedUsings.Any()) { expectedSubmissions.Add(string.Join(newLineCharacter, expectedUsings) + newLineCharacter); } AssertEx.Equal(expectedSubmissions, executedSubmissionCalls); testHost.Evaluator.OnExecute -= ExecuteSubmission; }
public TestContext(string projectLanguage = null, IEnumerable<string> metadataSources = null, bool includeXmlDocComments = false, string sourceWithSymbolReference = null) { projectLanguage = projectLanguage ?? LanguageNames.CSharp; metadataSources = metadataSources ?? SpecializedCollections.EmptyEnumerable<string>(); metadataSources = !metadataSources.Any() ? new[] { AbstractMetadataAsSourceTests.DefaultMetadataSource } : metadataSources; _workspace = CreateWorkspace(projectLanguage, metadataSources, includeXmlDocComments, sourceWithSymbolReference); _metadataAsSourceService = _workspace.GetService<IMetadataAsSourceFileService>(); _textBufferFactoryService = _workspace.GetService<ITextBufferFactoryService>(); }
private DiagnosticTaggerWrapper(TestWorkspace workspace, DiagnosticAnalyzerService analyzerService, IDiagnosticUpdateSource updateSource) { if (updateSource == null) { updateSource = analyzerService; } this.workspace = workspace; this.registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>(); registrationService.Register(workspace); this.asyncListener = new AsynchronousOperationListener(); var listeners = AsynchronousOperationListener.CreateListeners( ValueTuple.Create(FeatureAttribute.DiagnosticService, asyncListener), ValueTuple.Create(FeatureAttribute.ErrorSquiggles, asyncListener)); this.analyzerService = analyzerService; var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable(updateSource), listeners); this.TaggerProvider = new DiagnosticsSquiggleTaggerProvider( workspace.Services.GetService<IOptionService>(), diagnosticService, workspace.GetService<IForegroundNotificationService>(), listeners); if (analyzerService != null) { this.incrementalAnalyzers = ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace)); this.solutionCrawlerService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService; } }
public RenameTrackingTestState( string markup, string languageName, bool onBeforeGlobalSymbolRenamedReturnValue = true, bool onAfterGlobalSymbolRenamedReturnValue = true) { this.Workspace = CreateTestWorkspace(markup, languageName, TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic()); _hostDocument = Workspace.Documents.First(); _view = _hostDocument.GetTextView(); _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value)); _editorOperations = Workspace.GetService<IEditorOperationsFactoryService>().GetEditorOperations(_view); _historyRegistry = Workspace.ExportProvider.GetExport<ITextUndoHistoryRegistry>().Value; _mockRefactorNotifyService = new MockRefactorNotifyService { OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue, OnAfterSymbolRenamedReturnValue = onAfterGlobalSymbolRenamedReturnValue }; var optionService = this.Workspace.Services.GetService<IOptionService>(); // Mock the action taken by the workspace INotificationService var notificationService = Workspace.Services.GetService<INotificationService>() as INotificationServiceCallback; var callback = new Action<string, string, NotificationSeverity>((message, title, severity) => _notificationMessage = message); notificationService.NotificationCallback = callback; var tracker = new RenameTrackingTaggerProvider( _historyRegistry, Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value, Workspace.ExportProvider.GetExport<IInlineRenameService>().Value, Workspace.ExportProvider.GetExport<IDiagnosticAnalyzerService>().Value, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService), Workspace.ExportProvider.GetExports<IAsynchronousOperationListener, FeatureMetadata>()); _tagger = tracker.CreateTagger<RenameTrackingTag>(_hostDocument.GetTextBuffer()); if (languageName == LanguageNames.CSharp) { _codeFixProvider = new CSharpRenameTrackingCodeFixProvider( Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value, _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); } else if (languageName == LanguageNames.VisualBasic) { _codeFixProvider = new VisualBasicRenameTrackingCodeFixProvider( Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value, _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); } else { throw new ArgumentException("Invalid langauge name: " + languageName, "languageName"); } }
private IQuickInfoProvider CreateProvider(TestWorkspace workspace) { return new SyntacticQuickInfoProvider( workspace.GetService<ITextBufferFactoryService>(), workspace.GetService<IContentTypeRegistryService>(), workspace.GetService<IProjectionBufferFactoryService>(), workspace.GetService<IEditorOptionsFactoryService>(), workspace.GetService<ITextEditorFactoryService>(), workspace.GetService<IGlyphService>(), workspace.GetService<ClassificationTypeMap>()); }
internal static List<ITagSpan<IErrorTag>> GetErrorSpans( TestWorkspace workspace, ImmutableDictionary<string, ImmutableArray<DiagnosticAnalyzer>> analyzerMap = null) { var registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>(); registrationService.Register(workspace); var listener = new AsynchronousOperationListener(); var listeners = AsynchronousOperationListener.CreateListeners( ValueTuple.Create(FeatureAttribute.DiagnosticService, listener), ValueTuple.Create(FeatureAttribute.ErrorSquiggles, listener)); var optionsService = workspace.Services.GetService<IOptionService>(); var analyzerService = analyzerMap == null || analyzerMap.Count == 0 ? new TestDiagnosticAnalyzerService(DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap()) : new TestDiagnosticAnalyzerService(analyzerMap); var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable<IDiagnosticUpdateSource>(analyzerService), listeners); var document = workspace.Documents.First(); var buffer = document.GetTextBuffer(); var foregroundService = workspace.GetService<IForegroundNotificationService>(); var taggerProvider = new DiagnosticsSquiggleTaggerProvider(optionsService, diagnosticService, foregroundService, listeners); var tagger = taggerProvider.CreateTagger<IErrorTag>(buffer); using (var disposable = tagger as IDisposable) { var service = workspace.Services.GetService<ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService; service.WaitUntilCompletion_ForTestingPurposesOnly(workspace, ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace))); listener.CreateWaitTask().PumpingWait(); var snapshot = buffer.CurrentSnapshot; var spans = tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(snapshot, 0, snapshot.Length))).ToList(); registrationService.Unregister(workspace); return spans; } }
private async void AssertResetInteractive( TestWorkspace workspace, Project project, bool buildSucceeds, List<string> expectedSubmissions) { InteractiveWindowTestHost testHost = new InteractiveWindowTestHost(); List<string> executedSubmissionCalls = new List<string>(); EventHandler<string> ExecuteSubmission = (_, code) => { executedSubmissionCalls.Add(code); }; testHost.Evaluator.OnExecute += ExecuteSubmission; IWaitIndicator waitIndicator = workspace.GetService<IWaitIndicator>(); TestResetInteractive resetInteractive = new TestResetInteractive( waitIndicator, CreateReplReferenceCommand, CreateImport, buildSucceeds: buildSucceeds) { References = ImmutableArray.CreateRange(GetProjectReferences(workspace, project)), ReferenceSearchPaths = ImmutableArray.Create("rsp1", "rsp2"), SourceSearchPaths = ImmutableArray.Create("ssp1", "ssp2"), NamespacesToImport = ImmutableArray.Create("ns1", "ns2"), ProjectDirectory = "pj", }; await resetInteractive.Execute(testHost.Window, "Interactive C#"); // Validate that the project was rebuilt. Assert.Equal(1, resetInteractive.BuildProjectCount); Assert.Equal(0, resetInteractive.CancelBuildProjectCount); AssertEx.Equal(expectedSubmissions, executedSubmissionCalls); testHost.Evaluator.OnExecute -= ExecuteSubmission; }
private static async Task<List<IOutliningRegionTag>> GetTagsFromWorkspaceAsync(TestWorkspace workspace) { var hostdoc = workspace.Documents.First(); var view = hostdoc.GetTextView(); var textService = workspace.GetService<ITextEditorFactoryService>(); var editorService = workspace.GetService<IEditorOptionsFactoryService>(); var projectionService = workspace.GetService<IProjectionBufferFactoryService>(); var provider = new OutliningTaggerProvider( workspace.ExportProvider.GetExportedValue<IForegroundNotificationService>(), textService, editorService, projectionService, AggregateAsynchronousOperationListener.EmptyListeners); var document = workspace.CurrentSolution.GetDocument(hostdoc.Id); var context = new TaggerContext<IOutliningRegionTag>(document, view.TextSnapshot); await provider.ProduceTagsAsync_ForTestingPurposesOnly(context); return context.tagSpans.Select(x => x.Tag).ToList(); }
internal static IList<ITagSpan<IErrorTag>> GetErrorsFromUpdateSource(TestWorkspace workspace, TestHostDocument document, DiagnosticsUpdatedArgs updateArgs) { var source = new TestDiagnosticUpdateSource(); var listener = new AsynchronousOperationListener(); var listeners = AsynchronousOperationListener.CreateListeners( ValueTuple.Create(FeatureAttribute.DiagnosticService, listener), ValueTuple.Create(FeatureAttribute.ErrorSquiggles, listener)); var optionsService = workspace.Services.GetService<IOptionService>(); var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable<IDiagnosticUpdateSource>(source), listeners); var foregroundService = workspace.GetService<IForegroundNotificationService>(); //new TestForegroundNotificationService(); var buffer = document.GetTextBuffer(); var provider = new DiagnosticsSquiggleTaggerProvider(optionsService, diagnosticService, foregroundService, listeners); var tagger = provider.CreateTagger<IErrorTag>(buffer); source.RaiseDiagnosticsUpdated(updateArgs); listener.CreateWaitTask().PumpingWait(); var snapshot = buffer.CurrentSnapshot; var spans = tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(snapshot, 0, snapshot.Length))).ToImmutableArray(); ((IDisposable)tagger).Dispose(); return spans; }
public TestContext(TestWorkspace workspace) { _workspace = workspace; _metadataAsSourceService = _workspace.GetService<IMetadataAsSourceFileService>(); _textBufferFactoryService = _workspace.GetService<ITextBufferFactoryService>(); }
private CallHierarchyTestState(string markup, TestWorkspace workspace) { this.Workspace = workspace; var testDocument = Workspace.Documents.Single(d => d.CursorPosition.HasValue); _textView = testDocument.GetTextView(); _subjectBuffer = testDocument.GetTextBuffer(); var provider = Workspace.GetService<CallHierarchyProvider>(); var notificationService = Workspace.Services.GetService<INotificationService>() as INotificationServiceCallback; var callback = new Action<string, string, NotificationSeverity>((message, title, severity) => NotificationMessage = message); notificationService.NotificationCallback = callback; _presenter = new MockCallHierarchyPresenter(); _commandHandler = new CallHierarchyCommandHandler(new[] { _presenter }, provider, TestWaitIndicator.Default); }
public CallHierarchyTestState(XElement markup, params Type[] additionalTypes) { var exportProvider = CreateExportProvider(additionalTypes); this.Workspace = TestWorkspaceFactory.CreateWorkspace(markup, exportProvider: exportProvider); var testDocument = Workspace.Documents.Single(d => d.CursorPosition.HasValue); _textView = testDocument.GetTextView(); _subjectBuffer = testDocument.GetTextBuffer(); var provider = Workspace.GetService<CallHierarchyProvider>(); _presenter = new MockCallHierarchyPresenter(); _commandHandler = new CallHierarchyCommandHandler(new[] { _presenter }, provider, TestWaitIndicator.Default); }
private static List<IOutliningRegionTag> GetTagsFromWorkspace(TestWorkspace workspace) { var hostdoc = workspace.Documents.First(); var view = hostdoc.GetTextView(); var textService = workspace.GetService<ITextEditorFactoryService>(); var editorService = workspace.GetService<IEditorOptionsFactoryService>(); var projectionService = workspace.GetService<IProjectionBufferFactoryService>(); var provider = new OutliningTaggerProvider.TagProducer( textService, editorService, projectionService); Document document = workspace.CurrentSolution.GetDocument(hostdoc.Id); return provider.ProduceTagsAsync( document, new SnapshotSpan(view.TextSnapshot, 0, view.TextSnapshot.Length), null, CancellationToken.None).Result.Select(x => x.Tag).ToList(); }