public void CharacterSerialization() { var item = new { V1 = Rng.GetDouble().ToPercent(), V2 = Rng.GetDouble().ToPercent() }; var json = Jsonizer.Serialize(item); Console.WriteLine(json); Assert.AreEqual(json, json); }
public void JsonObjectOutput() { var item = new TestItem2 { Amount = Rng.GetDecimal() }; var expected = Jsonizer.Serialize(item, true); var actual = item.ToString(); Assert.AreEqual(expected, actual); }
public void CompareJsonFormatted() { var expected = Jsonizer.Serialize(Item, true); Console.WriteLine($"Expected: {expected}\n"); var clone = Jsonizer.Deserialize <TestItem0>(expected); var actual = Jsonizer.Serialize(clone, true); Console.WriteLine($" Actual: {actual}\n"); Assert.AreEqual(expected.GetHashCode(), actual.GetHashCode(), expected.Diff(actual).ToString()); }
public void DiffTest() { var item = Jsonizer.DeepCopy(JsonTests.Item); var expected = Jsonizer.Serialize(item); item.ListDate = Date.Today.AddDays(17); var actual = Jsonizer.Serialize(item); var diff = expected.Diff(actual); Console.WriteLine(diff); Assert.IsTrue(diff.DifferenceFound); Assert.IsTrue(diff.Expected.IsNotNullOrWhiteSpace()); Assert.IsTrue(diff.Actual.IsNotNullOrWhiteSpace()); Assert.AreNotEqual(diff.Expected, diff.Actual); }
public void CompareJsonSerializePerformance() { var r1 = Benchmark.Run(() => Newtonsoft.Json.JsonConvert.SerializeObject(Item)); var r2 = Benchmark.Run(() => Utf8Json.JsonSerializer.ToJsonString(Item)); var r3 = Benchmark.Run(() => System.Text.Json.JsonSerializer.Serialize(Item)); var r4 = Benchmark.Run(() => Jsonizer.Serialize(Item)); var stats = new StatsBuilder() .Add(typeof(Newtonsoft.Json.JsonConvert).FullName, r1) .Add(typeof(Utf8Json.JsonSerializer).FullName, r2) .Add(typeof(System.Text.Json.JsonSerializer).FullName, r3) .Add(typeof(Jsonizer).FullName, r4) .ToString(); Console.WriteLine(stats); Assert.IsTrue(r4.PerSecond > r1.PerSecond); }
public async Task CompareJsonSerializePerformance() { var r0 = await Benchmark.Run(() => Jsonizer.Serialize(Item)); var r1 = await Benchmark.Run(() => Newtonsoft.Json.JsonConvert.SerializeObject(Item)); var r2 = await Benchmark.Run(() => System.Text.Json.JsonSerializer.Serialize(Item)); var stats = new StatsBuilder() .Add(typeof(Jsonizer).FullName, r0) .Add(typeof(Newtonsoft.Json.JsonConvert).FullName, r1) .Add(typeof(System.Text.Json.JsonSerializer).FullName, r2) .ToString(); Console.WriteLine(stats); Assert.IsTrue(r0.PerSecond > r1.PerSecond); }
public override string ToString() => Jsonizer.Serialize(this, true);