/// <summary> /// verifyUndo is needed because of https://github.com/dotnet/roslyn/issues/28033 /// Most tests will continue to verifyUndo, but select tests will skip it due to /// this known test infrastructure issure. This bug does not represent a product /// failure. /// </summary> private void TestWorker( string inputMarkup, string expectedOutputMarkup, Action callback, bool verifyUndo = true, IndentStyle indentStyle = IndentStyle.Smart, bool useTabs = false) { using var workspace = TestWorkspace.CreateCSharp(inputMarkup); workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options .WithChangedOption(SmartIndent, LanguageNames.CSharp, indentStyle) .WithChangedOption(UseTabs, LanguageNames.CSharp, useTabs))); if (useTabs && expectedOutputMarkup != null) { Assert.Contains("\t", expectedOutputMarkup); } var document = workspace.Documents.Single(); var view = document.GetTextView(); var originalSnapshot = view.TextBuffer.CurrentSnapshot; var originalSelections = document.SelectedSpans; var snapshotSpans = new List <SnapshotSpan>(); foreach (var selection in originalSelections) { snapshotSpans.Add(selection.ToSnapshotSpan(originalSnapshot)); } view.SetMultiSelection(snapshotSpans); var undoHistoryRegistry = workspace.GetService <ITextUndoHistoryRegistry>(); var commandHandler = new SplitStringLiteralCommandHandler( undoHistoryRegistry, workspace.GetService <IEditorOperationsFactoryService>()); if (!commandHandler.ExecuteCommand(new ReturnKeyCommandArgs(view, view.TextBuffer), TestCommandExecutionContext.Create())) { callback(); } if (expectedOutputMarkup != null) { MarkupTestFile.GetSpans(expectedOutputMarkup, out var expectedOutput, out ImmutableArray <TextSpan> expectedSpans); Assert.Equal(expectedOutput, view.TextBuffer.CurrentSnapshot.AsText().ToString()); Assert.Equal(expectedSpans.First().Start, view.Caret.Position.BufferPosition.Position); if (verifyUndo) { // Ensure that after undo we go back to where we were to begin with. var history = undoHistoryRegistry.GetHistory(document.GetTextBuffer()); history.Undo(count: originalSelections.Count); var currentSnapshot = document.GetTextBuffer().CurrentSnapshot; Assert.Equal(originalSnapshot.GetText(), currentSnapshot.GetText()); Assert.Equal(originalSelections.First().Start, view.Caret.Position.BufferPosition.Position); } } }
public void SendSelectAll(Action <SelectAllCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new SelectAllCommandArgs(TextView, SubjectBuffer), nextHandler, TestCommandExecutionContext.Create());
public void SendToggleCompletionMode(Action <ToggleCompletionModeCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new ToggleCompletionModeCommandArgs(TextView, SubjectBuffer), nextHandler, TestCommandExecutionContext.Create());
public void SendInvokeSignatureHelp(Action <InvokeSignatureHelpCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new InvokeSignatureHelpCommandArgs(TextView, SubjectBuffer), nextHandler, TestCommandExecutionContext.Create());
public void SendTypeChar(char typeChar, Action <TypeCharCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new TypeCharCommandArgs(TextView, SubjectBuffer, typeChar), nextHandler, TestCommandExecutionContext.Create());
public bool SendInsertSnippetCommand(Func <InsertSnippetCommandArgs, CommandExecutionContext, bool> commandHandler) => commandHandler(new InsertSnippetCommandArgs(TextView, SubjectBuffer), TestCommandExecutionContext.Create());
public bool SendSurroundWithCommand(Func <SurroundWithCommandArgs, CommandExecutionContext, bool> commandHandler) => commandHandler(new SurroundWithCommandArgs(TextView, SubjectBuffer), TestCommandExecutionContext.Create());
public void SendCommitUniqueCompletionListItem(Action <CommitUniqueCompletionListItemCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new CommitUniqueCompletionListItemCommandArgs(TextView, SubjectBuffer), nextHandler, TestCommandExecutionContext.Create());
public void SendInsertSnippetCommand(Action <InsertSnippetCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new InsertSnippetCommandArgs(TextView, SubjectBuffer), nextHandler, TestCommandExecutionContext.Create());
public bool SendReturn(Func <ReturnKeyCommandArgs, CommandExecutionContext, bool> commandHandler) => commandHandler(new ReturnKeyCommandArgs(TextView, SubjectBuffer), TestCommandExecutionContext.Create());
public void SendPageDown(Action <PageDownKeyCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new PageDownKeyCommandArgs(TextView, SubjectBuffer), nextHandler, TestCommandExecutionContext.Create());
public bool SendBackTab(Func <BackTabKeyCommandArgs, CommandExecutionContext, bool> commandHandler) => commandHandler(new BackTabKeyCommandArgs(TextView, SubjectBuffer), TestCommandExecutionContext.Create());
public void SendBackTab(Action <BackTabKeyCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new BackTabKeyCommandArgs(TextView, SubjectBuffer), nextHandler, TestCommandExecutionContext.Create());
public void SendWordDeleteToStart(Action <WordDeleteToStartCommandArgs, Action, CommandExecutionContext> commandHandler, Action nextHandler) => commandHandler(new WordDeleteToStartCommandArgs(TextView, SubjectBuffer), nextHandler, TestCommandExecutionContext.Create());
public void SendEscape() { _commandHandler.ExecuteCommand(new EscapeKeyCommandArgs(_view, _view.TextBuffer), TestCommandExecutionContext.Create()); }
public void TestExtractMethodCommandHandlerErrorMessage() { var markupCode = @"class A { [|void Method() {}|] }"; using var workspace = TestWorkspace.CreateCSharp(markupCode, composition: EditorTestCompositions.EditorFeaturesWpf); var testDocument = workspace.Documents.Single(); var view = testDocument.GetTextView(); view.Selection.Select(new SnapshotSpan( view.TextBuffer.CurrentSnapshot, testDocument.SelectedSpans[0].Start, testDocument.SelectedSpans[0].Length), isReversed: false); var callBackService = workspace.Services.GetService <INotificationService>() as INotificationServiceCallback; var called = false; callBackService.NotificationCallback = (t, m, s) => called = true; var handler = workspace.ExportProvider.GetCommandHandler <ExtractMethodCommandHandler>(PredefinedCommandHandlerNames.ExtractMethod, ContentTypeNames.CSharpContentType); handler.ExecuteCommand(new ExtractMethodCommandArgs(view, view.TextBuffer), TestCommandExecutionContext.Create()); Assert.True(called); }