示例#1
0
        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);
        }
示例#2
0
        public void JsonObjectOutput()
        {
            var item = new TestItem2 {
                Amount = Rng.GetDecimal()
            };
            var expected = Jsonizer.Serialize(item, true);
            var actual   = item.ToString();

            Assert.AreEqual(expected, actual);
        }
示例#3
0
        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());
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
 public override string ToString() => Jsonizer.Serialize(this, true);