private static Document CreateDocument(string code, string language) { var solution = new CustomWorkspace(SolutionId.CreateNewId("Solution")).CurrentSolution; var projectId = ProjectId.CreateNewId(); var project = solution.AddProject(projectId, "Project", "Project.dll", language).GetProject(projectId); return project.AddMetadataReference(new MetadataFileReference(typeof(int).Assembly.Location)) .AddDocument("Document", SourceText.From(code)); }
private static Document CreateDocument(string code, string language) { var solution = new CustomWorkspace().CurrentSolution; var projectId = ProjectId.CreateNewId(); var project = solution.AddProject(projectId, "Project", "Project.dll", language).GetProject(projectId); return project.AddDocument("Document", SourceText.From(code)); }
public static Solution CreateOriginalDocument(string originalCode, CustomWorkspace workspace, out DocumentId documentId) { var projectId = workspace.AddProject("ProjectUnderTest", LanguageNames.CSharp); documentId = workspace.AddDocument(projectId, "SourceUnderTest.cs", originalCode); var solution = workspace.CurrentSolution .AddMetadataReference(projectId, mscorlib) .AddMetadataReference(projectId, System) .AddMetadataReference(projectId, SystemCore); return solution; }
public void TestWorkspaceDiagnosticHasDebuggerText() { var solution = new CustomWorkspace().CurrentSolution; WorkspaceDiagnostic diagnostic = null; solution.Workspace.WorkspaceFailed += (sender, args) => { diagnostic = args.Diagnostic; }; ProjectId pid = ProjectId.CreateNewId(); DocumentId did = DocumentId.CreateNewId(pid); solution = solution.AddProject(pid, "foo", "foo", LanguageNames.CSharp) .AddDocument(did, "x", new FileTextLoader("doesnotexist.cs")); var doc = solution.GetDocument(did); var text = doc.GetTextAsync().Result; WaitFor(() => diagnostic != null, TimeSpan.FromSeconds(5)); Assert.NotNull(diagnostic); var dd = diagnostic as DocumentDiagnostic; Assert.NotNull(dd); Assert.Equal(dd.GetDebuggerDisplay(), string.Format("[{0}] {1}", dd.Kind.ToString(), dd.Message)); }
public void TestDocumentFileAccessFailureMissingFile() { var solution = new CustomWorkspace().CurrentSolution; WorkspaceDiagnostic diagnostic = null; solution.Workspace.WorkspaceFailed += (sender, args) => { diagnostic = args.Diagnostic; }; ProjectId pid = ProjectId.CreateNewId(); DocumentId did = DocumentId.CreateNewId(pid); solution = solution.AddProject(pid, "foo", "foo", LanguageNames.CSharp) .AddDocument(did, "x", new FileTextLoader("doesnotexist.cs")); var doc = solution.GetDocument(did); var text = doc.GetTextAsync().Result; WaitFor(() => diagnostic != null, TimeSpan.FromSeconds(5)); Assert.NotNull(diagnostic); var dd = diagnostic as DocumentDiagnostic; Assert.NotNull(dd); Assert.Equal(did, dd.DocumentId); Assert.Equal(WorkspaceDiagnosticKind.FileAccessFailure, dd.Kind); }
public void TestLoadProjectFromCommandLine() { string commandLine = @"foo.cs subdir\bar.cs /out:foo.dll /target:library"; var ws = new CustomWorkspace(); var info = CommandLineProject.CreateProjectInfo(ws, "TestProject", LanguageNames.CSharp, commandLine, @"C:\ProjectDirectory"); ws.AddProject(info); var project = ws.CurrentSolution.GetProject(info.Id); Assert.Equal("TestProject", project.Name); Assert.Equal("foo", project.AssemblyName); Assert.Equal(OutputKind.DynamicallyLinkedLibrary, project.CompilationOptions.OutputKind); Assert.Equal(2, project.Documents.Count()); var fooDoc = project.Documents.First(d => d.Name == "foo.cs"); Assert.Equal(0, fooDoc.Folders.Count); Assert.Equal(@"C:\ProjectDirectory\foo.cs", fooDoc.FilePath); var barDoc = project.Documents.First(d => d.Name == "bar.cs"); Assert.Equal(1, barDoc.Folders.Count); Assert.Equal("subdir", barDoc.Folders[0]); Assert.Equal(@"C:\ProjectDirectory\subdir\bar.cs", barDoc.FilePath); }