public async Task ExtractsORMModelTree_When_MethodHasADbAccessingMethodCallStatement()
        {
            //Arrange
            var solGen   = new RoslynComplexSolutionGenerator();
            var solution = solGen.GetRoslynSolution();

            SyntaxNode rootNodeCustomerRepository
                = await solGen.GetRootNodeForCustomerRepositoryClassDocument();

            IEnumerable <MethodDeclarationSyntax> methodDeclarations = rootNodeCustomerRepository.DescendantNodes().OfType <MethodDeclarationSyntax>();

            SemanticModel model = await solGen.GetSemanticModelForCustomerRepositoryClass();

            await ExtractEntityDeclarations(solution);

            var dbQueryExtractor = new LINQToSQLDatabaseQueryExtractor(model, dbEntityDeclarations);

            dbQueryExtractor.Visit(rootNodeCustomerRepository);
            var databaseQueries = dbQueryExtractor.DatabaseQueries;

            target = new RoslynORMModelTreeExtractor(databaseQueries);
            //Act
            ORMModelTree result = target.Extract(methodDeclarations.First());

            //Assert
            Assert.IsTrue(result.RootNode.Model is MethodDeclaration);
            Assert.IsTrue((result.RootNode as MethodDeclaration).MethodName == "GetCustomer");

            Assert.IsTrue(result.RootNode.ChildNodes[0] is DatabaseAccessingMethodCallStatement <LINQToSQL>);
        }
コード例 #2
0
        private async Task ExtractDatabaseQueriesAsync(Solution solution)
        {
            foreach (var project in solution.Projects)
            {
                foreach (var documentId in project.DocumentIds)
                {
                    var document = solution.GetDocument(documentId);

                    SyntaxNode root = await Task.Run(() => document.GetSyntaxRootAsync());

                    SemanticModel model = await Task.Run(() => document.GetSemanticModelAsync());

                    var dbQueryExtractor = new LINQToSQLDatabaseQueryExtractor(model, DatabaseEntityDeclarations);
                    dbQueryExtractor.Visit(root);

                    foreach (var item in dbQueryExtractor.DatabaseQueries)
                    {
                        DatabaseQueries.Add(item);
                    }
                }
            }
        }