public void TestReport() { CoverageResult result = new CoverageResult(); result.Identifier = Guid.NewGuid().ToString(); Lines lines = new Lines(); lines.Add(1, 1); lines.Add(2, 0); Methods methods = new Methods(); var methodString = "System.Void Coverlet.Core.Reporters.Tests.JsonReporterTests.TestReport()"; methods.Add(methodString, new Method()); methods[methodString].Lines = lines; Classes classes = new Classes(); classes.Add("Coverlet.Core.Reporters.Tests.JsonReporterTests", methods); Documents documents = new Documents(); documents.Add("doc.cs", classes); result.Modules = new Modules(); result.Modules.Add("module", documents); JsonReporter reporter = new JsonReporter(); Assert.NotEqual("{\n}", reporter.Report(result, new Mock <ISourceRootTranslator>().Object)); Assert.NotEqual(string.Empty, reporter.Report(result, new Mock <ISourceRootTranslator>().Object)); }
public void TestReport() { CoverageResult result = new CoverageResult(); result.Identifier = Guid.NewGuid().ToString(); Lines lines = new Lines(); lines.Add(1, new LineInfo { Hits = 1 }); lines.Add(2, new LineInfo { Hits = 0 }); Methods methods = new Methods(); methods.Add("System.Void Coverlet.Core.Reporters.Tests.JsonReporterTests.TestReport()", lines); Classes classes = new Classes(); classes.Add("Coverlet.Core.Reporters.Tests.JsonReporterTests", methods); Documents documents = new Documents(); documents.Add("doc.cs", classes); result.Modules = new Modules(); result.Modules.Add("module", documents); JsonReporter reporter = new JsonReporter(); Assert.NotEqual("{\n}", reporter.Report(result)); Assert.NotEqual(string.Empty, reporter.Report(result)); }
public void ShouldShowSortedOrder() { using (var workspace = new AdhocWorkspace()) { workspace.AddSolution(SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create(), "c:\\ws\\app\\app.sln")); var p1 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "A", "A.dll", "C#", "c:\\ws\\app\\src\\A\\A.csproj"); var p2 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "B", "Y.dll", "C#", "c:\\ws\\app\\src\\B\\B.csproj"); using (var m = new MemoryStream()) { using (var sw = new StreamWriter(m)) { using (var reporter = new JsonReporter(sw)) { var a = workspace.AddProject(p1); var b = workspace.AddProject(p2); reporter.Report(a); reporter.Report(b); } sw.Flush(); } Assert.Equal(@"[ { ""Name"": ""A"", ""Order"": 0, ""AssemblyName"": ""A.dll"", ""FilePathFromSolutionDir"": ""src\\A\\A.csproj"" }, { ""Name"": ""B"", ""Order"": 1, ""AssemblyName"": ""Y.dll"", ""FilePathFromSolutionDir"": ""src\\B\\B.csproj"" } ] ".Replace("\r\n", "\n"), System.Text.Encoding.UTF8.GetString(m.ToArray()).Replace("\r\n", "\n")); } } }
public void TwoVulnerabilities() { var reporter = new JsonReporter(_consoleWrapper.Object); reporter.Start(); reporter.Report(new Vulnerability { Code = "ExampleCode", Title = "Example Vulnerability", SeverityLevel = SeverityLevel.Critical, Description = "Description here.", FilePath = "C:\\Program.cs", FullyQualifiedName = "Namespace.Class", LineNumber = 10 }); reporter.Report(new Vulnerability { Code = "ExampleCode2", Title = "Example Vulnerability", SeverityLevel = SeverityLevel.Critical, Description = "Description here.", FilePath = "C:\\Program.cs", FullyQualifiedName = "Namespace.Class", LineNumber = 20 }); reporter.Finish(); Assert.AreEqual(@"[ { ""Code"": ""ExampleCode"", ""Title"": ""Example Vulnerability"", ""SeverityLevel"": ""Critical"", ""Description"": ""Description here."", ""FilePath"": ""C:\\Program.cs"", ""FullyQualifiedName"": ""Namespace.Class"", ""LineNumber"": 10 }, { ""Code"": ""ExampleCode2"", ""Title"": ""Example Vulnerability"", ""SeverityLevel"": ""Critical"", ""Description"": ""Description here."", ""FilePath"": ""C:\\Program.cs"", ""FullyQualifiedName"": ""Namespace.Class"", ""LineNumber"": 20 } ] ".NormalizeEndOfLine(), _output.ToString()); }
/// <summary> /// caller sample: TestInstrumentationHelper.GenerateHtmlReport(result, sourceFileFilter: @"+**\Samples\Instrumentation.cs"); /// TestInstrumentationHelper.GenerateHtmlReport(result); /// </summary> public static void GenerateHtmlReport(CoverageResult coverageResult, IReporter reporter = null, string sourceFileFilter = "", [CallerMemberName] string directory = "") { JsonReporter defaultReporter = new JsonReporter(); reporter ??= new CoberturaReporter(); DirectoryInfo dir = Directory.CreateDirectory(directory); dir.Delete(true); dir.Create(); string reportFile = Path.Combine(dir.FullName, Path.ChangeExtension("report", defaultReporter.Extension)); File.WriteAllText(reportFile, defaultReporter.Report(coverageResult)); reportFile = Path.Combine(dir.FullName, Path.ChangeExtension("report", reporter.Extension)); File.WriteAllText(reportFile, reporter.Report(coverageResult)); // i.e. reportgenerator -reports:"C:\git\coverlet\test\coverlet.core.tests\bin\Debug\netcoreapp2.0\Condition_If\report.cobertura.xml" -targetdir:"C:\git\coverlet\test\coverlet.core.tests\bin\Debug\netcoreapp2.0\Condition_If" -filefilters:+**\Samples\Instrumentation.cs Assert.True(new Generator().GenerateReport(new ReportConfiguration( new[] { reportFile }, dir.FullName, new string[0], null, new string[0], new string[0], new string[0], new string[0], string.IsNullOrEmpty(sourceFileFilter) ? new string[0] : new[] { sourceFileFilter }, null, null))); }