Ejemplo n.º 1
0
        public RenameTrackingTestState(
            TestWorkspace workspace,
            string languageName,
            bool onBeforeGlobalSymbolRenamedReturnValue = true,
            bool onAfterGlobalSymbolRenamedReturnValue  = true
            )
        {
            this.Workspace = workspace;

            _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
            };

            // Mock the action taken by the workspace INotificationService
            var notificationService =
                (INotificationServiceCallback)Workspace.Services.GetRequiredService <INotificationService>();
            var callback = new Action <string, string, NotificationSeverity>(
                (message, title, severity) => _notificationMessage = message
                );

            notificationService.NotificationCallback = callback;

            var tracker = new RenameTrackingTaggerProvider(
                Workspace.ExportProvider.GetExportedValue <IThreadingContext>(),
                Workspace.ExportProvider.GetExport <IInlineRenameService>().Value,
                Workspace.ExportProvider.GetExport <IDiagnosticAnalyzerService>().Value,
                Workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>()
                );

            _tagger = tracker.CreateTagger <RenameTrackingTag>(_hostDocument.GetTextBuffer());

            if (languageName == LanguageNames.CSharp || languageName == LanguageNames.VisualBasic)
            {
                _codeRefactoringProvider = new RenameTrackingCodeRefactoringProvider(
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)
                    );
            }
            else
            {
                throw new ArgumentException(
                          "Invalid language name: " + languageName,
                          nameof(languageName)
                          );
            }
        }
Ejemplo n.º 2
0
        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");
            }
        }
Ejemplo n.º 3
0
        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");
            }
        }