public void TestFormat() { var mock = new Mock <IReporter>(); CoverageResult coverageResult = new CoverageResult(); coverageResult.Format(mock.Object); mock.Verify(m => m.Format(coverageResult)); }
public override bool Execute() { try { Console.WriteLine("\nCalculating coverage result..."); var coverage = InstrumentationTask.Coverage; CoverageResult result = coverage.GetCoverageResult(); var directory = Path.GetDirectoryName(_filename); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } Console.WriteLine($" Generating report '{_filename}'"); IReporter reporter = default(IReporter); switch (_format) { case "lcov": reporter = new LcovReporter(); break; case "opencover": reporter = new OpenCoverReporter(); break; default: reporter = new JsonReporter(); break; } File.WriteAllText(_filename, result.Format(reporter)); CoverageSummary coverageSummary = new CoverageSummary(result); var summary = coverageSummary.CalculateSummary(); ConsoleTable table = new ConsoleTable("Module", "Coverage"); foreach (var item in summary) { table.AddRow(item.Key, $"{item.Value}%"); } Console.WriteLine(); table.Write(Format.Alternative); } catch (Exception ex) { Log.LogErrorFromException(ex); return(false); } return(true); }