protected async Task VerifyAsync(string initialMarkup, string expectedMarkup) { using (var workspace = await CreateTestWorkspaceAsync(initialMarkup)) { var testDocument = workspace.Documents.Single(); var view = testDocument.GetTextView(); view.Caret.MoveTo(new SnapshotPoint(view.TextSnapshot, testDocument.CursorPosition.Value)); var commandHandler = CreateCommandHandler(workspace.GetService<ITextUndoHistoryRegistry>(), workspace.GetService<IEditorOperationsFactoryService>()); var args = new ReturnKeyCommandArgs(view, view.TextBuffer); var nextHandler = CreateInsertTextHandler(view, "\r\n"); commandHandler.ExecuteCommand(args, nextHandler); string expectedCode; int expectedPosition; MarkupTestFile.GetPosition(expectedMarkup, out expectedCode, out expectedPosition); Assert.Equal(expectedCode, view.TextSnapshot.GetText()); var caretPosition = view.Caret.Position.BufferPosition.Position; Assert.True(expectedPosition == caretPosition, string.Format("Caret positioned incorrectly. Should have been {0}, but was {1}.", expectedPosition, caretPosition)); } }
protected void VerifyPressingEnter(string initialMarkup, string expectedMarkup) { Verify(initialMarkup, expectedMarkup, (view, undoHistoryRegistry, editorOperationsFactoryService, completionService) => { var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService, completionService) as ICommandHandler<ReturnKeyCommandArgs>; var commandArgs = new ReturnKeyCommandArgs(view, view.TextBuffer); var nextHandler = CreateInsertTextHandler(view, "\r\n"); commandHandler.ExecuteCommand(commandArgs, nextHandler); }); }
protected async Task VerifyPressingEnterAsync(string initialMarkup, string expectedMarkup, bool useTabs = false, bool autoGenerateXmlDocComments = true) { await VerifyAsync(initialMarkup, expectedMarkup, useTabs, autoGenerateXmlDocComments, execute: (view, undoHistoryRegistry, editorOperationsFactoryService, completionService) => { var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService) as ICommandHandler<ReturnKeyCommandArgs>; var commandArgs = new ReturnKeyCommandArgs(view, view.TextBuffer); var nextHandler = CreateInsertTextHandler(view, "\r\n"); commandHandler.ExecuteCommand(commandArgs, nextHandler); }); }
protected static async Task AssertFormatWithPasteOrReturnAsync(string expectedWithMarker, string codeWithMarker, bool allowDocumentChanges, bool isPaste = true) { using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromLinesAsync(codeWithMarker)) { workspace.CanApplyChangeDocument = allowDocumentChanges; // set up caret position var testDocument = workspace.Documents.Single(); var view = testDocument.GetTextView(); view.Caret.MoveTo(new SnapshotPoint(view.TextSnapshot, testDocument.CursorPosition.Value)); // get original buffer var buffer = workspace.Documents.First().GetTextBuffer(); var optionService = workspace.Services.GetService<IOptionService>(); if (isPaste) { optionService.SetOptions(optionService.GetOptions().WithChangedOption(FeatureOnOffOptions.FormatOnPaste, LanguageNames.CSharp, true)); var commandHandler = new FormatCommandHandler(TestWaitIndicator.Default, null, null); var commandArgs = new PasteCommandArgs(view, view.TextBuffer); commandHandler.ExecuteCommand(commandArgs, () => { }); } else { // Return Key Command var textUndoHistory = new Mock<ITextUndoHistoryRegistry>(); var editorOperationsFactory = new Mock<IEditorOperationsFactoryService>(); var editorOperations = new Mock<IEditorOperations>(); editorOperationsFactory.Setup(x => x.GetEditorOperations(testDocument.GetTextView())).Returns(editorOperations.Object); var commandHandler = new FormatCommandHandler(TestWaitIndicator.Default, textUndoHistory.Object, editorOperationsFactory.Object); var commandArgs = new ReturnKeyCommandArgs(view, view.TextBuffer); commandHandler.ExecuteCommand(commandArgs, () => { }); } string expected; int expectedPosition; MarkupTestFile.GetPosition(expectedWithMarker, out expected, out expectedPosition); Assert.Equal(expected, view.TextSnapshot.GetText()); var caretPosition = view.Caret.Position.BufferPosition.Position; Assert.True(expectedPosition == caretPosition, string.Format("Caret positioned incorrectly. Should have been {0}, but was {1}.", expectedPosition, caretPosition)); } }
public CommandState GetCommandState(ReturnKeyCommandArgs args, Func<CommandState> nextHandler) { return nextHandler(); }
public void ExecuteCommand(ReturnKeyCommandArgs args, Action nextHandler) { ExecuteReturnOrTypeCommand(args, nextHandler, CancellationToken.None); }