static async Task<EditorInfo> CreateEditor (string text, bool isInCSharpContext) { string parsedText, editorText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var project = Services.ProjectService.CreateProject ("C#", "AspNetApp"); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); var sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.FileName = sev.ContentName; doc.UpdateProject (project); solution = new MonoDevelop.Projects.Solution (); solution.DefaultSolutionFolder.AddItem (project); solution.AddConfiguration ("", true); await TypeSystemServiceTestExtensions.LoadSolution (solution); var parser = new RazorTestingParser { Doc = doc }; var options = new ParseOptions { Project = project, FileName = sev.ContentName, Content = new StringTextSource (parsedText) }; var parsedDoc = (RazorCSharpParsedDocument)parser.Parse (options, default(CancellationToken)).Result; doc.HiddenParsedDocument = parsedDoc; var editorExtension = new RazorCSharpEditorExtension (doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext); return new EditorInfo { Extension = editorExtension, EditorText = editorText, View = sev }; }
static WebFormsTestingEditorExtension CreateEditor (string text, string extension, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var project = Services.ProjectService.CreateDotNetProject ("C#"); project.References.Add (ProjectReference.CreateAssemblyReference ("System")); project.References.Add (ProjectReference.CreateAssemblyReference ("System.Web")); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.FileName = sev.ContentName; var parser = new WebFormsParser (); var options = new ParseOptions { Project = project, FileName = sev.ContentName, Content = new StringTextSource (parsedText) }; var parsedDoc = (WebFormsParsedDocument)parser.Parse (options, default(CancellationToken)).Result; doc.HiddenParsedDocument = parsedDoc; return new WebFormsTestingEditorExtension (doc); }
static WebFormsTestingEditorExtension CreateEditor (string text, string extension, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var project = new AspNetAppProject ("C#"); project.References.Add (new ProjectReference (ReferenceType.Package, "System")); project.References.Add (new ProjectReference (ReferenceType.Package, "System.Web")); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); var pcw = TypeSystemService.LoadProject (project); TypeSystemService.ForceUpdate (pcw); pcw.ReconnectAssemblyReferences (); sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.Document.FileName = sev.ContentName; var parser = new WebFormsParser (); var parsedDoc = (WebFormsParsedDocument) parser.Parse (false, sev.ContentName, new StringReader (parsedText), project); doc.HiddenParsedDocument = parsedDoc; return new WebFormsTestingEditorExtension (doc); }
async Task<RazorCSharpParsedDocument> Parse (string text, bool isPreprocessed) { var project = Services.ProjectService.CreateDotNetProject ("C#", "AspNetApp"); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (".cshtml"); ProjectFile projectFile = project.AddFile (file); if (isPreprocessed) projectFile.Generator = "RazorTemplatePreprocessor"; var sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = text; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.FileName = sev.ContentName; doc.UpdateProject (project); solution = new MonoDevelop.Projects.Solution (); solution.DefaultSolutionFolder.AddItem (project); solution.AddConfiguration ("", true); await TypeSystemServiceTestExtensions.LoadSolution (solution); var parser = new RazorTestingParser { Doc = doc }; var options = new ParseOptions { Project = project, FileName = file, Content = new StringTextSource (text) }; return (RazorCSharpParsedDocument)parser.Parse (options, default(CancellationToken)).Result; }