Beispiel #1
0
        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 GetCurrentDocumentSemanticModel_Builds_Model_With_Necessary_Symbols()
        {
            _workspaceManager.CreateSolutionFile();
            _workspaceManager.NotifyNewExpectedProject();
            _workspaceManager.NotifyNewExpectedDocument();
            var pid1 = _workspaceManager.CreateProjectFile("TestProjectName1");
            var did1 = _workspaceManager.AddDocument(pid1, "TestDocumentName1", TestDocument1Text);

            var model = await _workspaceManager.GetCurrentDocumentSemanticModel(did1);

            var rootNode          = model.SyntaxTree.GetRoot();
            var descendantNodes   = rootNode.DescendantNodes();
            var classDeclaration  = descendantNodes.OfType <ClassDeclarationSyntax>().Single();
            var methodDeclaration = descendantNodes.OfType <MethodDeclarationSyntax>().Single();

            var classSymbol  = model.GetDeclaredSymbol(classDeclaration);
            var methodSymbol = model.GetDeclaredSymbol(methodDeclaration);

            Assert.AreEqual(classSymbol.Name, "TestClass1");
            Assert.AreEqual(methodSymbol.Name, "TestMethod1");
        }
Beispiel #3
0
        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()));
        }