public TestWorkspace GetWorkspace( string markup, ExportProvider exportProvider = null, string workspaceKind = null ) { // If it looks like XML, we'll treat it as XML; any parse error would be rejected and will throw. // We'll do a case insensitive search here so if somebody has a lowercase W it'll be tried (and // rejected by the XML parser) rather than treated as regular text. if (markup.TrimStart().StartsWith("<Workspace>", StringComparison.OrdinalIgnoreCase)) { CloseTextView(); _workspace?.Dispose(); _workspace = TestWorkspace.CreateWorkspace( XElement.Parse(markup), exportProvider: exportProvider, workspaceKind: workspaceKind ); _currentDocument = _workspace.Documents.First(d => d.CursorPosition.HasValue); Position = _currentDocument.CursorPosition.Value; Code = _currentDocument.GetTextBuffer().CurrentSnapshot.GetText(); return(_workspace); } else { MarkupTestFile.GetPosition(markup.NormalizeLineEndings(), out Code, out Position); var workspace = GetWorkspace(exportProvider); _currentDocument = workspace.Documents.Single(); return(workspace); } }
public void Dispose() { if (_workspace != null) { _workspace.Dispose(); _workspace = null; } }
public TestWorkspace GetWorkspace(string markup, ExportProvider exportProvider = null, string workspaceKind = null) { if (TryParseXElement(markup, out var workspaceElement) && workspaceElement.Name == "Workspace") { CloseTextView(); _workspace?.Dispose(); _workspace = TestWorkspace.CreateWorkspace(workspaceElement, exportProvider: exportProvider, workspaceKind: workspaceKind); _currentDocument = _workspace.Documents.First(d => d.CursorPosition.HasValue); Position = _currentDocument.CursorPosition.Value; Code = _currentDocument.GetTextBuffer().CurrentSnapshot.GetText(); return(_workspace); } else { MarkupTestFile.GetPosition(markup.NormalizeLineEndings(), out Code, out Position); var workspace = GetWorkspace(exportProvider); _currentDocument = workspace.Documents.Single(); return(workspace); } }
public void DisposeAfterTest() { try { CloseTextView(); _workspace?.Dispose(); } finally { _workspace = null; } }
public void DisposeAfterTest() { try { CloseTextView(); _currentDocument = null; Code = null; Position = 0; _workspace?.Dispose(); } finally { _workspace = null; } }
internal Holder CreateSession(TestWorkspace workspace, char opening, char closing, Dictionary<OptionKey, object> changedOptionSet = null) { var undoManager = workspace.ExportProvider.GetExportedValue<ITextBufferUndoManagerProvider>(); var editorOperationsFactoryService = workspace.ExportProvider.GetExportedValue<IEditorOperationsFactoryService>(); if (changedOptionSet != null) { var options = workspace.Options; foreach (var entry in changedOptionSet) { options = options.WithChangedOption(entry.Key, entry.Value); } workspace.Options = options; } var document = workspace.Documents.First(); var provider = new BraceCompletionSessionProvider(undoManager, editorOperationsFactoryService); var openingPoint = new SnapshotPoint(document.GetTextBuffer().CurrentSnapshot, document.CursorPosition.Value); IBraceCompletionSession session; if (provider.TryCreateSession(document.GetTextView(), openingPoint, opening, closing, out session)) { return new Holder(workspace, session); } workspace.Dispose(); return null; }