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 TestWorkspace GetWorkspace(string markup, ExportProvider exportProvider = null) { if (TryParseXElement(markup, out var workspaceElement) && workspaceElement.Name == "Workspace") { _workspace = TestWorkspace.CreateWorkspace(workspaceElement, exportProvider: exportProvider); _currentDocument = _workspace.Documents.First(d => d.CursorPosition.HasValue); Position = _currentDocument.CursorPosition.Value; Code = _currentDocument.TextBuffer.CurrentSnapshot.GetText(); return(_workspace); } else { MarkupTestFile.GetPosition(markup.NormalizeLineEndings(), out Code, out Position); var workspace = GetWorkspace(exportProvider); _currentDocument = workspace.Documents.Single(); return(workspace); } }