public async Task Build_Recognizes_Class_Type(Type targetType, string testFileName, string testDocumentText) { _workspaceManager.NotifyNewExpectedDocument(); var testDocumentPath = Path.Combine("C:", "Directory1", "Directory2", testFileName); var did = _workspaceManager.AddDocument(_primaryProjectId, "TestDocument", testDocumentText); var model = await _workspaceManager.GetCurrentDocumentSemanticModel(did); var classConverter = _classConverterFactory.BuildMany(testDocumentPath, model).Single(); Assert.IsInstanceOf(targetType, classConverter); }
public async Task GetNamespaceLevelTypes_Retrieves_All_Types(string testDocumentText) { _workspaceManager.NotifyNewExpectedProject(); _workspaceManager.NotifyNewExpectedDocument(); var pid1 = _workspaceManager.CreateProjectFile("TestProjectName1"); var did1 = _workspaceManager.AddDocument(pid1, "TestDocumentName1", testDocumentText); var syntaxTree = await _workspaceManager.GetCurrentDocumentSyntaxTree(did1); var testTypeNodes = syntaxTree.GetRoot().DescendantNodes().OfType <TypeDeclarationSyntax>(); var testType1 = testTypeNodes.Single(node => node.Identifier.ToString().Equals("TestType1")); var testType2 = testTypeNodes.Single(node => node.Identifier.ToString().Equals("TestType2")); var types = syntaxTree.GetNamespaceLevelTypes(); Assert.True(types.Contains(testType1)); Assert.True(types.Contains(testType2)); }
public async Task GetNamespacesReferencedByType_Does_Not_Contain_Own_Namespace() { _workspaceManager.NotifyNewExpectedProject(); _workspaceManager.NotifyNewExpectedDocument(); var pid1 = _workspaceManager.CreateProjectFile("TestProjectName1"); var did1 = _workspaceManager.AddDocument(pid1, "TestDocumentName1", TestDocument1NamespaceText); var model = await _workspaceManager.GetCurrentDocumentSemanticModel(did1); var treeNodes = model.SyntaxTree.GetRoot().DescendantNodes(); var testClass1Declaration = treeNodes.OfType <ClassDeclarationSyntax>().Single(node => node.Identifier.ToString().Equals("TestClass1")); var classSymbol = model.GetDeclaredSymbol(testClass1Declaration); var requiredNamespaces = model.GetNamespacesReferencedByType(testClass1Declaration); Assert.False(requiredNamespaces.Contains(classSymbol?.ContainingNamespace?.ToDisplayString())); }
public void AddDocument_Adds_Single_Document_To_Project() { _workspaceManager.CreateSolutionFile(); _workspaceManager.NotifyNewExpectedProject(); _workspaceManager.NotifyNewExpectedProject(); _workspaceManager.NotifyNewExpectedDocument(); var pid1 = _workspaceManager.CreateProjectFile("TestProjectName1"); var pid2 = _workspaceManager.CreateProjectFile("TestProjectName2"); _workspaceManager.AddDocument(pid2, "TestDocumentName", ""); var project1 = _workspaceManager.CurrentSolution.Projects.Where(project => project.Name.Equals("TestProjectName1")).Single(); var project2 = _workspaceManager.CurrentSolution.Projects.Where(project => project.Name.Equals("TestProjectName2")).Single(); Assert.AreEqual(project1.Documents.Count(), 0); Assert.AreEqual(project2.Documents.Count(), 1); }