public void ContainsDependenciesFromDifferentProject() { var pidA = ProjectId.CreateNewId("A"); var pidB = ProjectId.CreateNewId("B"); var didA = DocumentId.CreateNewId(pidA); var didB = DocumentId.CreateNewId(pidB); const string docA = @" namespace A { public class Button {public void Bar(){}} } "; const string docB = @" namespace B { class GuiFacade { public void Foo(){new A.Button().Bar();} public static void Main(){} } } "; var solution = MSBuildWorkspace.Create(new Dictionary<string, string> { { "CheckForSystemRuntimeDependency", "true" } }).CurrentSolution .AddProject(pidA, "ProjectA", "A.dll", LanguageNames.CSharp) .AddDocument(didA, "A.cs", docA) .AddProject(pidB, "ProjectB", "B.dll", LanguageNames.CSharp) .AddDocument(didB, "B.cs", docB) .AddProjectReference(pidB, new ProjectReference(pidA)); var tree = new SolutionNode(); tree.AddChild(new ProjectNode {Documents = solution.GetProject(pidA).Documents }); tree.AddChild(new ProjectNode { Documents = solution.GetProject(pidB).Documents }); ClassTreeBuilder.AddClassesInProjectsToTree(tree); var button = tree.DescendantNodes().WithName("Button") as ClassNode; var guiFacade = tree.DescendantNodes().WithName("GuiFacade"); button.Should().NotBeNull(); guiFacade.Should().NotBeNull(); guiFacade.Dependencies.Should().NotBeEmpty(); }
public static DisposableResult BuildProjectTreeFromDocuments(params string[] documentContents) { var fakeWorkspace = new AdhocWorkspace(); var project = fakeWorkspace.AddProject("ProjectA", LanguageNames.CSharp); var i = 0; foreach (var content in documentContents) { fakeWorkspace.AddDocument(project.Id, "doc" + i, SourceText.From(content)); i++; } var projectA = new ProjectNode { Documents = fakeWorkspace.CurrentSolution .GetProject(project.Id).Documents }; var tree = new SolutionNode(); tree.AddChild(projectA); ClassTreeBuilder.AddClassesInProjectsToTree(tree); return new DisposableResult {Workspace = fakeWorkspace, result = projectA}; }