public CoverageResult CalculateForMethod(string projectName, MethodDeclarationSyntax method) { var projects = _testExplorer.GetUnignoredTestProjectsWithCoveredProjectsAsync().Result; var project = projects.FirstOrDefault(x => x.Name == projectName); if (project == null) return new CoverageResult(new LineCoverage[0]); var rewritter = new SolutionRewriter(new RewrittenDocumentsStorage(), _auditVariablesRewriter); RewrittenDocument rewrittenDocument = rewritter.RewriteDocumentWithAssemblyInfo(project, projects, method.SyntaxTree.FilePath, method.SyntaxTree.ToString()); LineCoverage[] coverage = null; using (var appDomainTestExecutorScriptEngine = new AppDomainTestExecutorScriptEngine()) { var lineCoverageCalc = new LineCoverageCalc(_testExplorer, new RoslynCompiler(), new TestRunner(new NUnitTestExtractor(), appDomainTestExecutorScriptEngine, _solutionExplorer)); coverage = lineCoverageCalc.CalculateForMethod(project, rewrittenDocument, method); } _coverageStore.Append(coverage); return new CoverageResult(coverage); }
public async Task<CoverageResult> CalculateForAllDocumentsAsync() { var rewritter = new SolutionRewriter(new RewrittenDocumentsStorage(), _auditVariablesRewriter); //TODO: Change a method to async and don't use .Result var projects = await _testExplorer.GetUnignoredTestProjectsWithCoveredProjectsAsync().ConfigureAwait(false); RewriteResult rewrittenResult = rewritter.RewriteAllClasses(projects); LineCoverage[] coverage = null; using (var appDomainTestExecutorScriptEngine = new AppDomainTestExecutorScriptEngine()) { var lineCoverageCalc = new LineCoverageCalc(_testExplorer, new RoslynCompiler(), new TestRunner(new NUnitTestExtractor(), appDomainTestExecutorScriptEngine, _solutionExplorer)); coverage = lineCoverageCalc.CalculateForAllTests(rewrittenResult); } _coverageStore.WriteAll(coverage); return new CoverageResult(coverage); }