Exemplo n.º 1
0
        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();
            await sev.Initialize(new FileDescriptor (file, null, project), null);

            sev.Text            = text;
            sev.Editor.FileName = sev.FilePath;

            solution = new MonoDevelop.Projects.Solution();
            solution.DefaultSolutionFolder.AddItem(project);
            solution.AddConfiguration("", true);
            await TypeSystemServiceTestExtensions.LoadSolution(solution);

            var parser = new RazorTestingParser {
                Editor = sev.Editor
            };
            var options = new ParseOptions {
                Project  = project,
                FileName = file,
                Content  = new StringTextSource(text)
            };

            return((RazorCSharpParsedDocument)parser.Parse(options, default(CancellationToken)).Result);
        }
        static RazorTestingEditorExtension CreateEditor(string text, bool isInCSharpContext, 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.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 Document(tww);
            var parser = new RazorTestingParser {
                Doc = doc
            };
            var parsedDoc = parser.Parse(false, sev.ContentName, new StringReader(parsedText), project);

            return(new RazorTestingEditorExtension(doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext));
        }
Exemplo n.º 3
0
        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 = await parser.Parse(options, default(CancellationToken)) as RazorCSharpParsedDocument;

            doc.HiddenParsedDocument = parsedDoc;

            var editorExtension = new RazorCSharpEditorExtension(doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext);

            return(new EditorInfo {
                Extension = editorExtension,
                EditorText = editorText,
                View = sev
            });
        }
		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
			};
		}
		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;
		}
		static RazorTestingEditorExtension CreateEditor (string text, bool isInCSharpContext, 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.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 Document (tww);
			var parser = new RazorTestingParser {
				Doc = doc
			};
			var parsedDoc = parser.Parse (false, sev.ContentName, new StringReader (parsedText), project);

			return new RazorTestingEditorExtension (doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext);
		}