private static void CommentOrUncommentSelection( ITextView textView, IEnumerable <TextChange> expectedChanges, IEnumerable <Span> expectedSelectedSpans, bool supportBlockComments, Operation operation) { var textUndoHistoryRegistry = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <ITextUndoHistoryRegistry>(); var editorOperationsFactory = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <IEditorOperationsFactoryService>(); var commandHandler = new CommentUncommentSelectionCommandHandler(textUndoHistoryRegistry, editorOperationsFactory); var service = new MockCommentSelectionService(supportBlockComments); var edits = commandHandler.CollectEditsAsync( null, service, textView.TextBuffer, textView.Selection.GetSnapshotSpansOnBuffer(textView.TextBuffer), operation, CancellationToken.None).GetAwaiter().GetResult(); Roslyn.Test.Utilities.AssertEx.SetEqual(expectedChanges, edits.TextChanges); var trackingSpans = edits.TrackingSpans .Select(textSpan => AbstractCommentSelectionBase <Operation> .CreateTrackingSpan( edits.ResultOperation, textView.TextBuffer.CurrentSnapshot, textSpan.TrackingTextSpan)) .ToList(); // Actually apply the edit to let the tracking spans adjust. using (var edit = textView.TextBuffer.CreateEdit()) { edits.TextChanges.Do(tc => edit.Replace(tc.Span.ToSpan(), tc.NewText)); edit.Apply(); } if (trackingSpans.Any()) { textView.SetSelection(trackingSpans.First().GetSpan(textView.TextBuffer.CurrentSnapshot)); } if (expectedSelectedSpans != null) { Roslyn.Test.Utilities.AssertEx.Equal(expectedSelectedSpans, textView.Selection.SelectedSpans.Select(snapshotSpan => snapshotSpan.Span)); } }
private static void CommentOrUncommentSelection( ITextView textView, IEnumerable <TextChange> expectedChanges, IEnumerable <Span> expectedSelectedSpans, bool supportBlockComments, CommentUncommentSelectionCommandHandler.Operation operation) { var textUndoHistoryRegistry = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <ITextUndoHistoryRegistry>(); var editorOperationsFactory = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <IEditorOperationsFactoryService>(); var commandHandler = new CommentUncommentSelectionCommandHandler(TestWaitIndicator.Default, textUndoHistoryRegistry, editorOperationsFactory); var service = new MockCommentSelectionService(supportBlockComments); var trackingSpans = new List <ITrackingSpan>(); var textChanges = new List <TextChange>(); commandHandler.CollectEdits( null, service, textView.Selection.GetSnapshotSpansOnBuffer(textView.TextBuffer), textChanges, trackingSpans, operation, CancellationToken.None); AssertEx.SetEqual(expectedChanges, textChanges); // Actually apply the edit to let the tracking spans adjust. using (var edit = textView.TextBuffer.CreateEdit()) { textChanges.Do(tc => edit.Replace(tc.Span.ToSpan(), tc.NewText)); edit.Apply(); } if (trackingSpans.Any()) { textView.SetSelection(trackingSpans.First().GetSpan(textView.TextSnapshot)); } if (expectedSelectedSpans != null) { AssertEx.Equal(expectedSelectedSpans, textView.Selection.SelectedSpans.Select(snapshotSpan => snapshotSpan.Span)); } }