public void SimpleJson_ReplaceUnsupportedNumericValues_Smoke(object val1, object val2, object val3) { //Arrange var data = new List <object>() { val1, val2, val3 }; //Act for (int i = 0; i < data.Count; i++) { data[i] = JsonSerializer.ReplaceUnsupportedNumericValues(data[i]); } //Assert Assert.Equal(val1, data[0]); Assert.Equal(val2, data[1]); Assert.Equal(JsonSerializer.JSON_EMPTY_STRING, data[2]); }
public void SimpleJson_SerializeObjectWithUnsupportedNumericValues_ReturnsValidJson() { //Arrange var data = new Dictionary <string, object> { { "Statistic1", float.NaN }, { "Statistic2", float.NegativeInfinity }, { "Statistic3", float.PositiveInfinity }, { "Statistic4", double.NaN }, { "Statistic5", double.NegativeInfinity }, { "Statistic6", double.PositiveInfinity } }; //Act string json = JsonSerializer.SerializeObject(data); //Assert Assert.True(JsonSerializer.TryDeserializeObject(json, out var obj)); var values = (obj as SimpleJson.JsonObject).Select(x => x.Value); Assert.True(values.All(x => x.Equals(string.Empty))); }
public override void ExportToLog(Summary summary, ILogger logger) { // We construct HostEnvironmentInfo manually, so that we can have the HardwareTimerKind enum as text, rather than an integer // SimpleJson serializer doesn't seem to have an enum String/Value option (to-be-fair, it is meant to be "Simple") var environmentInfo = new { HostEnvironmentInfo.BenchmarkDotNetCaption, summary.HostEnvironmentInfo.BenchmarkDotNetVersion, OsVersion = summary.HostEnvironmentInfo.OsVersion.Value, ProcessorName = ProcessorBrandStringHelper.Prettify(summary.HostEnvironmentInfo.CpuInfo.Value?.ProcessorName ?? ""), summary.HostEnvironmentInfo.CpuInfo.Value?.PhysicalProcessorCount, summary.HostEnvironmentInfo.CpuInfo.Value?.PhysicalCoreCount, summary.HostEnvironmentInfo.CpuInfo.Value?.LogicalCoreCount, summary.HostEnvironmentInfo.RuntimeVersion, summary.HostEnvironmentInfo.Architecture, summary.HostEnvironmentInfo.HasAttachedDebugger, summary.HostEnvironmentInfo.HasRyuJit, summary.HostEnvironmentInfo.Configuration, summary.HostEnvironmentInfo.JitModules, DotNetCliVersion = summary.HostEnvironmentInfo.DotNetSdkVersion.Value, summary.HostEnvironmentInfo.ChronometerFrequency, HardwareTimerKind = summary.HostEnvironmentInfo.HardwareTimerKind.ToString() }; // If we just ask SimpleJson to serialise the entire "summary" object it throws several errors. // So we are more specific in what we serialise (plus some fields/properties aren't relevant) var benchmarks = summary.Reports.Select(r => { var data = new Dictionary <string, object> { // We don't need Benchmark.ShortInfo, that info is available via Benchmark.Parameters below { "DisplayInfo", r.BenchmarkCase.DisplayInfo }, { "Namespace", r.BenchmarkCase.Descriptor.Type.Namespace }, { "Type", FullNameProvider.GetTypeName(r.BenchmarkCase.Descriptor.Type) }, { "Method", r.BenchmarkCase.Descriptor.WorkloadMethod.Name }, { "MethodTitle", r.BenchmarkCase.Descriptor.WorkloadMethodDisplayInfo }, { "Parameters", r.BenchmarkCase.Parameters.PrintInfo }, { "FullName", FullNameProvider.GetBenchmarkName(r.BenchmarkCase) }, // do NOT remove this property, it is used for xunit-performance migration // { "Properties", r.Benchmark.Job.ToSet().ToDictionary(p => p.Name, p => p.Value) }, // TODO { "Statistics", r.ResultStatistics } }; // We show MemoryDiagnoser's results only if it is being used if (summary.Config.HasMemoryDiagnoser()) { data.Add("Memory", r.GcStats); } if (ExcludeMeasurements == false) { // We construct Measurements manually, so that we can have the IterationMode enum as text, rather than an integer data.Add("Measurements", r.AllMeasurements.Select(m => new { IterationMode = m.IterationMode.ToString(), IterationStage = m.IterationStage.ToString(), m.LaunchIndex, m.IterationIndex, m.Operations, m.Nanoseconds })); } return(data); }); JsonSerializer.CurrentJsonSerializerStrategy.Indent = IndentJson; logger.WriteLine(JsonSerializer.SerializeObject(new Dictionary <string, object> { { "Title", summary.Title }, { "HostEnvironmentInfo", environmentInfo }, { "Benchmarks", benchmarks } })); }
public override void ExportToLog(Summary summary, ILogger logger) { // We construct HostEnvironmentInfo manually, so that we can have the HardwareTimerKind enum as text, rather than an integer // SimpleJson serialiser doesn't seem to have an enum String/Value option (to-be-fair, it is meant to be "Simple") var environmentInfo = new { HostEnvironmentInfo.BenchmarkDotNetCaption, summary.HostEnvironmentInfo.BenchmarkDotNetVersion, summary.HostEnvironmentInfo.OsVersion, summary.HostEnvironmentInfo.ProcessorName, summary.HostEnvironmentInfo.ProcessorCount, summary.HostEnvironmentInfo.RuntimeVersion, summary.HostEnvironmentInfo.Architecture, summary.HostEnvironmentInfo.HasAttachedDebugger, summary.HostEnvironmentInfo.HasRyuJit, summary.HostEnvironmentInfo.Configuration, summary.HostEnvironmentInfo.JitModules, DotNetCliVersion = summary.HostEnvironmentInfo.DotNetCliVersion.Value, summary.HostEnvironmentInfo.ChronometerFrequency, HardwareTimerKind = summary.HostEnvironmentInfo.HardwareTimerKind.ToString() }; // If we just ask SimpleJson to serialise the entire "summary" object it throws several errors. // So we are more specific in what we serialise (plus some fields/properties aren't relevant) var benchmarks = summary.Reports.Select(r => { var data = new Dictionary <string, object> { // We don't need Benchmark.ShortInfo, that info is available via Benchmark.Parameters below { "DisplayInfo", r.Benchmark.DisplayInfo }, { "Namespace", r.Benchmark.Target.Type.Namespace }, { "Type", r.Benchmark.Target.Type.Name }, { "Method", r.Benchmark.Target.Method.Name }, { "MethodTitle", r.Benchmark.Target.MethodDisplayInfo }, { "Parameters", r.Benchmark.Parameters.PrintInfo }, // { "Properties", r.Benchmark.Job.ToSet().ToDictionary(p => p.Name, p => p.Value) }, // TODO { "Statistics", r.ResultStatistics }, }; if (ExcludeMeasurements == false) { // We construct Measurements manually, so that we can have the IterationMode enum as text, rather than an integer data.Add("Measurements", r.AllMeasurements.Select(m => new { IterationMode = m.IterationMode.ToString(), m.LaunchIndex, m.IterationIndex, m.Operations, m.Nanoseconds })); } return(data); }); JsonSerialiser.CurrentJsonSerializerStrategy.Indent = IndentJson; logger.WriteLine(JsonSerialiser.SerializeObject(new Dictionary <string, object> { { "Title", summary.Title }, { "HostEnvironmentInfo", environmentInfo }, { "Benchmarks", benchmarks } })); }
public override void ExportToLog(Summary summary, ILogger logger) { JsonSerializer.CurrentJsonSerializerStrategy.Indent = IndentJson; logger.WriteLine(JsonSerializer.SerializeObject(GetDataToSerialize(summary))); }