public void Set_serialization(PocoJsonSerializerMode mode) { using var logGroup = TestHelper.Monitor.OpenInfo($"{nameof(Set_serialization)}-{mode}"); var c = TestHelper.CreateStObjCollector(typeof(PocoJsonSerializer), typeof(ITestSetNumbers)); using var s = TestHelper.CreateAutomaticServices(c).Services; var directory = s.GetRequiredService <PocoDirectory>(); var f = s.GetRequiredService <IPocoFactory <ITestSetNumbers> >(); var o = f.Create(o => { o.Power = 3712; o.Hip += "CodeGen!"; o.Numbers.AddRangeArray(12, 87, 12, 54, 12); }); var o2 = JsonTestHelper.Roundtrip(directory, o, new PocoJsonSerializerOptions { Mode = mode }, text: t => TestHelper.Monitor.Info(t)); Debug.Assert(o2 != null); o2.Power.Should().Be(o.Power); o2.Hip.Should().Be(o.Hip); o2.Numbers.Should().BeEquivalentTo(o.Numbers); }
public void all_basic_types_roundtrip(PocoJsonSerializerMode mode) { var c = TestHelper.CreateStObjCollector(typeof(PocoJsonSerializer), typeof(IAllBasicTypes));; using var services = TestHelper.CreateAutomaticServices(c).Services; var directory = services.GetRequiredService <PocoDirectory>(); var nMax = services.GetRequiredService <IPocoFactory <IAllBasicTypes> >().Create(); nMax.PByte = Byte.MaxValue; nMax.PSByte = SByte.MaxValue; nMax.PShort = Int16.MaxValue; nMax.PUShort = UInt16.MaxValue; nMax.PInteger = Int32.MaxValue; nMax.PUInteger = UInt32.MaxValue; nMax.PLong = Int64.MaxValue; nMax.PULong = UInt64.MaxValue; nMax.PFloat = Single.MaxValue; nMax.PDouble = Double.MaxValue; nMax.PDecimal = Decimal.MaxValue; nMax.PBigInteger = BigInteger.Parse("12345678901234567890123456789012345678901234567890123456789012345678901234567890", System.Globalization.NumberFormatInfo.InvariantInfo); nMax.PDateTime = Util.UtcMaxValue; nMax.PDateTimeOffset = DateTimeOffset.MaxValue; nMax.PTimeSpan = TimeSpan.MaxValue; nMax.PGuid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"); var nMin = services.GetRequiredService <IPocoFactory <IAllBasicTypes> >().Create(); nMin.PByte = Byte.MinValue; nMin.PSByte = SByte.MinValue; nMin.PShort = Int16.MinValue; nMin.PUShort = UInt16.MinValue; nMin.PInteger = Int32.MinValue; nMin.PUInteger = UInt32.MinValue; nMin.PLong = Int64.MinValue; nMin.PULong = UInt64.MinValue; nMin.PFloat = Single.MinValue; nMin.PDouble = Double.MinValue; nMin.PDecimal = Decimal.MinValue; nMin.PBigInteger = BigInteger.Parse("-12345678901234567890123456789012345678901234567890123456789012345678901234567890", System.Globalization.NumberFormatInfo.InvariantInfo); nMin.PDateTime = Util.UtcMinValue; nMin.PDateTimeOffset = DateTimeOffset.MinValue; nMin.PTimeSpan = TimeSpan.MinValue; nMin.PGuid = Guid.Empty; var options = new PocoJsonSerializerOptions { Mode = mode }; var nMax2 = JsonTestHelper.Roundtrip(directory, nMax, options, text: t => TestHelper.Monitor.Info($"IAllBasicTypes(max) serialization: " + t)); nMax2.Should().BeEquivalentTo(nMax); var nMin2 = JsonTestHelper.Roundtrip(directory, nMin, options, text: t => TestHelper.Monitor.Info($"IAllBasicTypes(min) serialization: " + t)); nMin2.Should().BeEquivalentTo(nMin); }