public static void RoundtripSerializeDeserialize___Using_TestMapping_with_all_defaults___Works() { // Arrange var bsonConfigType = typeof(TypesToRegisterBsonSerializationConfiguration <TestMapping>); var jsonConfigType = typeof(TypesToRegisterJsonSerializationConfiguration <TestMapping>); var expected = new TestMapping(); void ThrowIfObjectsDiffer(DescribedSerializationBase describedSerialization, TestMapping deserialized) { deserialized.Should().NotBeNull(); deserialized.StringProperty.Should().BeNull(); deserialized.IntProperty.Should().Be(default(int)); deserialized.DateTimePropertyUtc.Should().Be(default(DateTime)); deserialized.DateTimePropertyLocal.Should().Be(default(DateTime)); deserialized.DateTimePropertyUnspecified.Should().Be(default(DateTime)); deserialized.GuidProperty.Should().Be(Guid.Empty); deserialized.NonEnumArray.Should().BeNull(); deserialized.EnumArray.Should().BeNull(); deserialized.StringIntMap.Should().BeNull(); deserialized.EnumIntMap.Should().BeNull(); deserialized.IntIntTuple.Should().BeNull(); deserialized.EnumProperty.Should().Be(TestEnumeration.None); deserialized.IntArray.Should().BeNull(); } // Act & Assert expected.RoundtripSerializeWithCallbackVerification(ThrowIfObjectsDiffer, bsonConfigType, jsonConfigType); }
public static void RoundtripSerializeDeserialize___Using_TestMapping___Works() { // Arrange var bsonConfigType = typeof(TypesToRegisterBsonSerializationConfiguration <TestMapping>); var jsonConfigType = typeof(TypesToRegisterJsonSerializationConfiguration <TestMapping>); var expected = new TestMapping { StringProperty = Guid.NewGuid().ToString(), IntProperty = A.Dummy <int>(), DateTimePropertyUtc = DateTime.UtcNow, DateTimePropertyLocal = DateTime.UtcNow.ToLocalTime(), DateTimePropertyUnspecified = DateTime.UtcNow.ToUnspecified(), GuidProperty = Guid.NewGuid(), NonEnumArray = new[] { A.Dummy <string>() }, EnumArray = new[] { A.Dummy <TestEnumeration>(), }, StringIntMap = new Dictionary <string, int> { { "key", A.Dummy <int>() } }, EnumIntMap = new Dictionary <AnotherEnumeration, int> { { A.Dummy <AnotherEnumeration>(), A.Dummy <int>() } }, IntIntTuple = new Tuple <int, int>(3, 4), EnumProperty = A.Dummy <TestEnumeration>(), IntArray = A.Dummy <int[]>(), }; void ThrowIfObjectsDiffer(DescribedSerializationBase describedSerialization, TestMapping deserialized) { deserialized.Should().NotBeNull(); deserialized.StringProperty.Should().Be(expected.StringProperty); deserialized.IntProperty.Should().Be(expected.IntProperty); deserialized.DateTimePropertyUtc.Kind.Should().Be(DateTimeKind.Utc); deserialized.DateTimePropertyUtc.Should().Be(expected.DateTimePropertyUtc); deserialized.DateTimePropertyLocal.Should().Be(expected.DateTimePropertyLocal); deserialized.DateTimePropertyLocal.Kind.Should().Be(DateTimeKind.Local); deserialized.DateTimePropertyUnspecified.Should().Be(expected.DateTimePropertyUnspecified); deserialized.DateTimePropertyUnspecified.Kind.Should().Be(DateTimeKind.Unspecified); deserialized.GuidProperty.Should().Be(expected.GuidProperty); deserialized.NonEnumArray.Single().Should().Be(expected.NonEnumArray.Single()); deserialized.EnumArray.Single().Should().Be(expected.EnumArray.Single()); deserialized.StringIntMap.Single().Should().Be(expected.StringIntMap.Single()); deserialized.EnumIntMap.Single().Should().Be(expected.EnumIntMap.Single()); deserialized.IntIntTuple.Should().Be(expected.IntIntTuple); deserialized.EnumProperty.Should().Be(expected.EnumProperty); deserialized.IntArray.Should().Equal(expected.IntArray); } // Act & Assert expected.RoundtripSerializeWithCallbackVerification(ThrowIfObjectsDiffer, bsonConfigType, jsonConfigType); }