public void TestFormat() { 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(); methods.Add("System.Void Coverlet.Core.Reporters.Tests.JsonReporterTests.TestFormat()", 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.Format(result)); Assert.NotEqual(string.Empty, reporter.Format(result)); }
/// <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))); }
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 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 OneVulnerability() { 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.Finish(); Assert.AreEqual(@"[ { ""Code"": ""ExampleCode"", ""Title"": ""Example Vulnerability"", ""SeverityLevel"": ""Critical"", ""Description"": ""Description here."", ""FilePath"": ""C:\\Program.cs"", ""FullyQualifiedName"": ""Namespace.Class"", ""LineNumber"": 10 } ] ".NormalizeEndOfLine(), _output.ToString()); }
private void GenerateJsonReportsButton_Click(object sender, EventArgs e) { var currentDir = Directory.GetCurrentDirectory(); var destinationDir = new DirectoryInfo(JsonOutputReports); JsonReporter.CreateReports(new SqlServerDb(), destinationDir); MessageBox.Show(JsonReportsAreGeneratedSuccessfuly, string.Empty, MessageBoxButtons.OK); }
public static async Task Walk(string solutionPath, MSBuildWorkspace workspace) { var solution = await workspace.OpenSolutionAsync(solutionPath); using (var progress = new JsonReporter(Console.Out)) { var walker = new SolutionWalker(); walker.Walk(solution, progress, progress); } }
public void NoVulnerabilities() { var reporter = new JsonReporter(_consoleWrapper.Object); reporter.Start(); reporter.Finish(); Assert.AreEqual(@"[] ".NormalizeEndOfLine(), _output.ToString()); }
public void WriteToFolder(string folderPath, bool clearDirectory = false) { var jsPath = Path.Combine(folderPath, "js"); var cssPath = Path.Combine(folderPath, "css"); if (clearDirectory && Directory.Exists(folderPath)) { foreach (var dir in Directory.GetDirectories(folderPath)) { Directory.Delete(dir, true); } foreach (var file in Directory.GetFiles(folderPath)) { File.Delete(file); } } if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } if (!Directory.Exists(jsPath)) { Directory.CreateDirectory(jsPath); } if (!Directory.Exists(cssPath)) { Directory.CreateDirectory(cssPath); } // index.html File.WriteAllText(Path.Combine(folderPath, "index.html"), ApplySettings(Resources.index_html) ); // css/styles.min.css File.WriteAllText(Path.Combine(cssPath, "styles.min.css"), Resources.styles_min_css ); // js/scripts.min.js File.WriteAllText(Path.Combine(jsPath, "scripts.min.js"), ApplySettings(Resources.scripts_min_js) ); // js/scripts.min.map File.WriteAllText(Path.Combine(jsPath, "scripts.min.map"), ApplySettings(Resources.scripts_min_map) ); // js/reportdata.js File.WriteAllText(Path.Combine(jsPath, "report-data.js"), string.Format("var reportData = {0};", JsonReporter.WriteToString()) ); WriteFontFiles(folderPath); }
public void JsonReporter_OnAllMutantsTestedShouldWriteJsonToFile() { var mockFileSystem = new MockFileSystem(); var options = new StrykerOptions(thresholdBreak: 0, thresholdHigh: 80, thresholdLow: 60); var reporter = new JsonReporter(options, mockFileSystem); reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith()); var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.json"); mockFileSystem.FileExists(reportPath).ShouldBeTrue($"Path {reportPath} should exist but it does not."); }
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); }
public void ShouldCloseArray() { using (var m = new MemoryStream()) { using (var sw = new StreamWriter(m)) { using (var reporter = new JsonReporter(sw)) { } sw.Flush(); } Assert.Equal(@"[ ] ".Replace("\r\n", "\n"), System.Text.Encoding.UTF8.GetString(m.ToArray()).Replace("\r\n", "\n")); } }
public void JsonReporter_OnAllMutantsTestedShouldWriteJsonToFile() { var mockFileSystem = new MockFileSystem(); var options = new StrykerOptions { Thresholds = new Thresholds { High = 80, Low = 60, Break = 0 }, OutputPath = Directory.GetCurrentDirectory(), ReportFileName = "mutation-report" }; var reporter = new JsonReporter(options, mockFileSystem); reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith()); var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.json"); mockFileSystem.FileExists(reportPath).ShouldBeTrue($"Path {reportPath} should exist but it does not."); var fileContents = mockFileSystem.File.ReadAllText(reportPath); fileContents.ShouldContain(@"""thresholds"":{"); fileContents.ShouldContain(@"""high"":80"); fileContents.ShouldContain(@"""low"":60"); }
private void btnRaporAl_Click_1(object sender, EventArgs e) { dietToPatientDto = patientManager.GetDietToPatientDto(_hastaDetay.Id); patientToDietDto = patientManager.GetPatientToDietDto(_hastaDetay.Id); if (cmbRapor.Text == "JSON") { JsonReporter jsonReporter = new JsonReporter(); if (cmbSiralama.Text == "Önce hasta bilgisi, sonra diyet") { jsonReporter.CreateJson(patientToDietDto, "userData.json"); } else { jsonReporter.CreateJson(dietToPatientDto, "userData.json"); } } else if (cmbRapor.Text == "HTML") { HtmlReporter htmlReporter = new HtmlReporter(); if (cmbSiralama.Text == "Önce hasta bilgisi, sonra diyet") { htmlReporter.build(patientToDietDto, true); } else { htmlReporter.build(patientToDietDto, false); } } MessageBox.Show("Rapor oluşturuldu !"); this.Hide(); }
public ZipkinTracerOptions WithJsonReporter(JsonReporterOptions options = null) { Reporter = new JsonReporter(this, options ?? new JsonReporterOptions()); return(this); }
public void JsonReporter_OnAllMutantsTestedShouldWriteJsonToFile() { var tree = CSharpSyntaxTree.ParseText("void M(){ int i = 0 + 8; }"); var originalNode = tree.GetRoot().DescendantNodes().OfType <BinaryExpressionSyntax>().First(); var mutation = new Mutation() { OriginalNode = originalNode, ReplacementNode = SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, originalNode.Left, originalNode.Right), DisplayName = "This name should display", Type = Mutator.Arithmetic }; var folder = new FolderComposite() { Name = "RootFolder" }; folder.Add(new FileLeaf() { Name = "SomeFile.cs", Mutants = new Collection <Mutant>() { new Mutant() { Id = 55, ResultStatus = MutantStatus.Killed, Mutation = mutation } }, SourceCode = "void M(){ int i = 0 + 8; }" }); folder.Add(new FileLeaf() { Name = "SomeOtherFile.cs", Mutants = new Collection <Mutant>() { new Mutant() { Id = 56, ResultStatus = MutantStatus.Survived, Mutation = mutation } }, SourceCode = "void M(){ int i = 0 + 8; }" }); folder.Add(new FileLeaf() { Name = "SomeOtherFile.cs", Mutants = new Collection <Mutant>() { new Mutant() { Id = 56, ResultStatus = MutantStatus.Skipped, Mutation = mutation } }, SourceCode = "void M(){ int i = 0 + 8; }" }); var mockFileSystem = new MockFileSystem(); var options = new StrykerOptions(thresholdBreak: 0, thresholdHigh: 80, thresholdLow: 60); var reporter = new JsonReporter(options, mockFileSystem); reporter.OnAllMutantsTested(folder); var reportPath = Path.Combine(options.BasePath, "StrykerOutput", "reports", $"mutation-report-{DateTime.Today.ToString("yyyy-MM-dd")}.json"); mockFileSystem.FileExists(reportPath).ShouldBeTrue($"Path {reportPath} should exist but it does not."); var reportObject = JsonConvert.DeserializeObject <JsonReporter.JsonReportComponent>(mockFileSystem.GetFile(reportPath).TextContents); reportObject.ThresholdHigh.ShouldBe(80); reportObject.ThresholdLow.ShouldBe(60); reportObject.ThresholdBreak.ShouldBe(0); ValidateJsonReportComponent(reportObject, folder, "Warning"); ValidateJsonReportComponent(reportObject.ChildResults.ElementAt(0), folder.Children.ElementAt(0), "Good", 1); ValidateJsonReportComponent(reportObject.ChildResults.ElementAt(1), folder.Children.ElementAt(1), "Danger", 1); }