public static void RoundtripSerialize___Should_use_element_serializer___When_serializers_are_registered() { // Arrange var modelThatSerializesToString = new ModelThatSerializesToString(-603, 329); var expected1 = new CollectionsOfModelThatSerializesToStringModel { CollectionInterface = new List <ModelThatSerializesToString> { modelThatSerializesToString }, ReadOnlyCollectionInterface = new HashSet <ModelThatSerializesToString> { modelThatSerializesToString }, ListInterface = new List <ModelThatSerializesToString> { modelThatSerializesToString }, ReadOnlyListInterface = new[] { modelThatSerializesToString }, List = new List <ModelThatSerializesToString> { modelThatSerializesToString }, Collection = new Collection <ModelThatSerializesToString> { modelThatSerializesToString }, ReadOnlyCollection = new ReadOnlyCollection <ModelThatSerializesToString>(new List <ModelThatSerializesToString> { modelThatSerializesToString }), }; var expected2 = A.Dummy <CollectionsOfModelThatSerializesToStringModel>(); void ThrowIfObjectsDiffer(DescribedSerializationBase describedSerialization, CollectionsOfModelThatSerializesToStringModel deserialized) { deserialized.AsTest().Must().BeEqualTo(expected1); if (describedSerialization is StringDescribedSerialization stringDescribedSerialization) { stringDescribedSerialization.SerializedPayload.AsTest().Must().ContainString("-603,329"); } } // Act, Assert expected1.RoundtripSerializeViaBsonWithCallbackVerification(ThrowIfObjectsDiffer, typeof(CollectionsOfModelThatSerializesToStringBsonSerializationConfiguration)); expected2.RoundtripSerializeViaBsonWithBeEqualToAssertion(typeof(CollectionsOfModelThatSerializesToStringBsonSerializationConfiguration)); }
public static void RoundtripSerialize___Should_return_types_that_honor_mutability_contracts___When_deserializing_various_system_collection_types() { // Arrange var modelThatSerializesToString = A.Dummy <TestModel>(); var expected = new CollectionsOfModelThatSerializesToStringModel { CollectionInterface = new List <TestModel> { modelThatSerializesToString }, ReadOnlyCollectionInterface = new HashSet <TestModel> { modelThatSerializesToString }, ListInterface = new List <TestModel> { modelThatSerializesToString }, ReadOnlyListInterface = new[] { modelThatSerializesToString }, List = new List <TestModel> { modelThatSerializesToString }, Collection = new Collection <TestModel> { modelThatSerializesToString }, ReadOnlyCollection = new ReadOnlyCollection <TestModel>(new List <TestModel> { modelThatSerializesToString }), }; void ThrowIfObjectsDiffer(DescribedSerializationBase describedSerialization, CollectionsOfModelThatSerializesToStringModel deserialized) { // these types are mutable; we should be able to add to them deserialized.Collection.Add(null); deserialized.CollectionInterface.Add(null); deserialized.List.Add(null); deserialized.ListInterface.Add(null); } // Act, Assert expected.RoundtripSerializeViaJsonWithCallbackVerification(ThrowIfObjectsDiffer, typeof(CollectionsOfTestModelJsonSerializationConfiguration)); }