public void OpenCoverMethodMetricsTest() { var filterMock = new Mock <IFilter>(); filterMock.Setup(f => f.IsElementIncludedInReport(It.IsAny <string>())).Returns(true); string filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "MultiOpenCover.xml"); var parserResult = new CoverageReportParser(1, 1, new string[0], filterMock.Object, filterMock.Object, filterMock.Object).ParseFiles(new string[] { filePath }); var metrics = parserResult.Assemblies .Single(a => a.Name == "Test").Classes .Single(c => c.Name == "Test.TestClass").Files .Single(f => f.Path == "C:\\temp\\TestClass.cs") .MethodMetrics; Assert.Equal(2, metrics.Count()); Assert.Equal("System.Void Test.TestClass::SampleFunction()", metrics.First().FullName); Assert.Equal(3, metrics.First().Metrics.Count()); Assert.Equal("Cyclomatic complexity", metrics.First().Metrics.ElementAt(0).Name); Assert.Equal(3, metrics.First().Metrics.ElementAt(0).Value); Assert.Equal("Sequence coverage", metrics.First().Metrics.ElementAt(1).Name); Assert.Equal(222, metrics.First().Metrics.ElementAt(1).Value); Assert.Equal("Branch coverage", metrics.First().Metrics.ElementAt(2).Name); Assert.Equal(333, metrics.First().Metrics.ElementAt(2).Value); }
public void ParseFiles_SeveralReportFilesWithSeveralReports_CorrectParserIsReturned() { string filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "NCover1.5.8.xml"); string filePath2 = Path.Combine(FileManager.GetCSharpReportDirectory(), "MultiOpenCover.xml"); string parserName = new CoverageReportParser(1, 1, new string[0], this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath, filePath2 }).ParserName; Assert.Equal("MultiReportParser (1x NCoverParser, 2x OpenCoverParser)", parserName); }
private ParserResult ParseCoverageFiles(List <string> coverageFiles) { CoverageReportParser parser = new CoverageReportParser(1, new string[] { }, new DefaultFilter(new string[] { }), new DefaultFilter(new string[] { }), new DefaultFilter(new string[] { })); ReadOnlyCollection <string> collection = new ReadOnlyCollection <string>(coverageFiles); return(parser.ParseFiles(collection)); }
private ParserResult ParseCoverageFiles(List <string> coverageFiles) { TraceLogger.Debug("ReportGeneratorTool.ParseCoverageFiles: Parsing coverage files."); CoverageReportParser parser = new CoverageReportParser(1, 1, new string[] { }, new DefaultFilter(new string[] { }), new DefaultFilter(new string[] { }), new DefaultFilter(new string[] { })); ReadOnlyCollection <string> collection = new ReadOnlyCollection <string>(coverageFiles); return(parser.ParseFiles(collection)); }
public void ParseFiles_SingleReportFileWithSingleReport_CorrectParserIsReturned() { string filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "NCover1.5.8.xml"); var parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("NCoverParser", parserResult.ParserName); Assert.Equal(0, parserResult.SourceDirectories.Count); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "OpenCover.xml"); parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("OpenCoverParser", parserResult.ParserName); Assert.Equal(0, parserResult.SourceDirectories.Count); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "dotCover.xml"); parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("DotCoverParser", parserResult.ParserName); Assert.Equal(0, parserResult.SourceDirectories.Count); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "VisualStudio2010.coveragexml"); parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("VisualStudioParser", parserResult.ParserName); Assert.Equal(0, parserResult.SourceDirectories.Count); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "DynamicCodeCoverage.xml"); parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("DynamicCodeCoverageParser", parserResult.ParserName); Assert.Equal(0, parserResult.SourceDirectories.Count); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "mprof-report.xml"); parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("MProfParser", parserResult.ParserName); Assert.Equal(0, parserResult.SourceDirectories.Count); filePath = Path.Combine(FileManager.GetJavaReportDirectory(), "Cobertura2.1.1.xml"); parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("CoberturaParser", parserResult.ParserName); Assert.Equal(1, parserResult.SourceDirectories.Count); Assert.Equal("C:/temp", parserResult.SourceDirectories.First()); filePath = Path.Combine(FileManager.GetJavaReportDirectory(), "JaCoCo0.8.3.xml"); parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("JaCoCoParser", parserResult.ParserName); Assert.Equal(1, parserResult.SourceDirectories.Count); Assert.Equal("C:\\somedirectory", parserResult.SourceDirectories.First()); filePath = Path.Combine(FileManager.GetJavaReportDirectory(), "Clover_OpenClover4.3.1.xml"); parserResult = new CoverageReportParser(1, new string[] { "C:\\somedirectory" }, this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }); Assert.Equal("CloverParser", parserResult.ParserName); Assert.Equal(1, parserResult.SourceDirectories.Count); Assert.Equal("C:\\somedirectory", parserResult.SourceDirectories.First()); }
public IActionResult GetCoverageDetails() { var parser = new CoverageReportParser(1, 1, new List <string>(), new DefaultFilter(new List <string>()), new DefaultFilter(new List <string>()), new DefaultFilter(new List <string>())); IReadOnlyCollection <string> testCoverageFilePath = new Collection <string>() { "" }; var parserResult = parser.ParseFiles(testCoverageFilePath); return(Ok(parserResult)); }
public void OpenCoverBranchesTest() { var filterMock = new Mock <IFilter>(); filterMock.Setup(f => f.IsElementIncludedInReport(It.IsAny <string>())).Returns(true); string filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "MultiOpenCover.xml"); var parserResult = new CoverageReportParser(1, 1, new string[0], filterMock.Object, filterMock.Object, filterMock.Object).ParseFiles(new string[] { filePath }); var fileAnalysis = GetFileAnalysis(parserResult.Assemblies, "Test.TestClass2", "C:\\temp\\TestClass2.cs"); Assert.False(fileAnalysis.Lines.Single(l => l.LineNumber == 44).CoveredBranches.HasValue, "No covered branches"); Assert.False(fileAnalysis.Lines.Single(l => l.LineNumber == 44).TotalBranches.HasValue, "No total branches"); Assert.Equal(1, fileAnalysis.Lines.Single(l => l.LineNumber == 45).CoveredBranches.Value); Assert.Equal(2, fileAnalysis.Lines.Single(l => l.LineNumber == 45).TotalBranches.Value); }
public void ParseFiles_SingleReportFileWithSeveralReports_CorrectParserIsReturned() { string filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "MultiNCover1.5.8.xml"); string parserName = new CoverageReportParser(1, 1, new string[0], this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }).ParserName; Assert.Equal("MultiReportParser (2x NCoverParser)", parserName); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "MultiOpenCover.xml"); parserName = new CoverageReportParser(1, 1, new string[0], this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }).ParserName; Assert.Equal("MultiReportParser (2x OpenCoverParser)", parserName); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "MultidotCover.xml"); parserName = new CoverageReportParser(1, 1, new string[0], this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }).ParserName; Assert.Equal("MultiReportParser (2x DotCoverParser)", parserName); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "MultiVisualStudio2010.coveragexml"); parserName = new CoverageReportParser(1, 1, new string[0], this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }).ParserName; Assert.Equal("MultiReportParser (2x VisualStudioParser)", parserName); filePath = Path.Combine(FileManager.GetCSharpReportDirectory(), "MultiDynamicCodeCoverage.xml"); parserName = new CoverageReportParser(1, 1, new string[0], this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { filePath }).ParserName; Assert.Equal("MultiReportParser (2x DynamicCodeCoverageParser)", parserName); }
public void ParseFiles_NoReports_CorrectParserIsReturned() { string parserName = new CoverageReportParser(1, 1, new string[0], this.filterMock.Object, this.filterMock.Object, this.filterMock.Object).ParseFiles(new string[] { string.Empty }).ParserName; Assert.Equal(string.Empty, parserName); }
/// <summary> /// Executes the report generation. /// </summary> /// <param name="reportConfiguration">The report configuration.</param> /// <returns><c>true</c> if report was generated successfully; otherwise <c>false</c>.</returns> public bool GenerateReport(IReportConfiguration reportConfiguration) { if (reportConfiguration == null) { throw new ArgumentNullException(nameof(reportConfiguration)); } try { var configuration = this.GetConfiguration(); var reportContext = new ReportContext(reportConfiguration); configuration.GetSection("settings").Bind(reportContext.Settings); var pluginLoader = new ReflectionPluginLoader(reportConfiguration.Plugins); IReportBuilderFactory reportBuilderFactory = new ReportBuilderFactory(pluginLoader); // Set log level before validation is performed LoggerFactory.VerbosityLevel = reportContext.ReportConfiguration.VerbosityLevel; if (!new ReportConfigurationValidator(reportBuilderFactory).Validate(reportContext.ReportConfiguration)) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); DateTime executionTime = DateTime.Now; var parserResult = new CoverageReportParser( reportContext.Settings.NumberOfReportsParsedInParallel, reportConfiguration.SourceDirectories, new DefaultFilter(reportContext.ReportConfiguration.AssemblyFilters), new DefaultFilter(reportContext.ReportConfiguration.ClassFilters), new DefaultFilter(reportContext.ReportConfiguration.FileFilters)) .ParseFiles(reportContext.ReportConfiguration.ReportFiles); Logger.DebugFormat(Resources.ReportParsingTook, stopWatch.ElapsedMilliseconds / 1000d); var riskHotspotsAnalysisThresholds = new RiskHotspotsAnalysisThresholds(); configuration.GetSection("riskHotspotsAnalysisThresholds").Bind(riskHotspotsAnalysisThresholds); reportContext.RiskHotspotAnalysisResult = new RiskHotspotsAnalyzer(riskHotspotsAnalysisThresholds) .PerformRiskHotspotAnalysis(parserResult.Assemblies); var overallHistoricCoverages = new System.Collections.Generic.List <Parser.Analysis.HistoricCoverage>(); var historyStorage = new HistoryStorageFactory(pluginLoader).GetHistoryStorage(reportContext.ReportConfiguration); if (historyStorage != null) { new HistoryParser(historyStorage, reportContext.Settings.MaximumNumberOfHistoricCoverageFiles) .ApplyHistoricCoverage(parserResult.Assemblies, overallHistoricCoverages); reportContext.OverallHistoricCoverages = overallHistoricCoverages; } new Reporting.ReportGenerator( parserResult, reportBuilderFactory.GetReportBuilders(reportContext)) .CreateReport(reportContext.ReportConfiguration.HistoryDirectory != null, overallHistoricCoverages, executionTime, reportContext.ReportConfiguration.Tag); if (historyStorage != null) { new HistoryReportGenerator(historyStorage) .CreateReport(parserResult.Assemblies, executionTime, reportContext.ReportConfiguration.Tag); } stopWatch.Stop(); Logger.InfoFormat(Resources.ReportGenerationTook, stopWatch.ElapsedMilliseconds / 1000d); return(true); } catch (Exception ex) { Logger.Error(ex.GetExceptionMessageForDisplay()); Logger.Error(ex.StackTrace); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } }
/// <summary> /// Generates a report using given configuration. /// </summary> /// <param name="reportConfiguration">The report configuration.</param> /// <param name="settings">The settings.</param> /// <param name="riskHotspotsAnalysisThresholds">The risk hotspots analysis thresholds.</param> /// <returns><c>true</c> if report was generated successfully; otherwise <c>false</c>.</returns> public bool GenerateReport( IReportConfiguration reportConfiguration, Settings settings, RiskHotspotsAnalysisThresholds riskHotspotsAnalysisThresholds) { if (reportConfiguration == null) { throw new ArgumentNullException(nameof(reportConfiguration)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (riskHotspotsAnalysisThresholds == null) { throw new ArgumentNullException(nameof(riskHotspotsAnalysisThresholds)); } try { var pluginLoader = new ReflectionPluginLoader(reportConfiguration.Plugins); IReportBuilderFactory reportBuilderFactory = new ReportBuilderFactory(pluginLoader); // Set log level before validation is performed LoggerFactory.VerbosityLevel = reportConfiguration.VerbosityLevel; Logger.Info($"{Resources.Executable}: {typeof(Program).Assembly.Location}"); Logger.Info($"{Resources.WorkingDirectory}: {Directory.GetCurrentDirectory()}"); if (!new ReportConfigurationValidator(reportBuilderFactory).Validate(reportConfiguration)) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } Logger.Debug(Resources.Settings); Logger.Debug(" " + JsonSerializer.ToJsonString(settings)); Logger.Debug(" " + JsonSerializer.ToJsonString(riskHotspotsAnalysisThresholds)); var stopWatch = Stopwatch.StartNew(); var parserResult = new CoverageReportParser( settings.NumberOfReportsParsedInParallel, settings.NumberOfReportsMergedInParallel, reportConfiguration.SourceDirectories, new DefaultFilter(reportConfiguration.AssemblyFilters), new DefaultFilter(reportConfiguration.ClassFilters), new DefaultFilter(reportConfiguration.FileFilters)) .ParseFiles(reportConfiguration.ReportFiles); Logger.DebugFormat(Resources.ReportParsingTook, stopWatch.ElapsedMilliseconds / 1000d); this.GenerateReport( reportConfiguration, settings, riskHotspotsAnalysisThresholds, parserResult); stopWatch.Stop(); Logger.InfoFormat(Resources.ReportGenerationTook, stopWatch.ElapsedMilliseconds / 1000d); return(true); } catch (Exception ex) { Logger.Error(ex.GetExceptionMessageForDisplay()); Logger.Error(ex.StackTrace); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } }