@@ -25,7 +25,7 @@ namespace MongoDB.Driver.Tests
2525 public class MultipleRegistriesTests
2626 {
2727 [ Fact ]
28- public void GeneralTest ( )
28+ public void TestSerialization ( )
2929 {
3030 // At the moment having this uncommented would make the test fail due to the static caching of class maps
3131 // {
@@ -73,13 +73,46 @@ public void GeneralTest()
7373 }
7474 }
7575
76+ [ Fact ]
77+ public void TestDeserialization ( )
78+ {
79+ {
80+ var client = DriverTestConfiguration . CreateMongoClient ( ) ;
81+ var db = client . GetDatabase ( DriverTestConfiguration . DatabaseNamespace . DatabaseName ) ;
82+ db . DropCollection ( DriverTestConfiguration . CollectionNamespace . CollectionName ) ;
83+ var collection = db . GetCollection < Person1 > ( DriverTestConfiguration . CollectionNamespace . CollectionName ) ;
84+
85+ var person = new Person1 { Id = ObjectId . Parse ( "6797b56bf5495bf53aa3078f" ) , Name = "Mariotest" , Age = 24 } ;
86+ collection . InsertOne ( person ) ;
87+ }
88+
89+ {
90+ var customDomain = BsonSerializer . CreateDomain ( ) ;
91+ customDomain . RegisterSerializer ( new CustomStringSerializer ( ) ) ;
92+
93+ var client = DriverTestConfiguration . CreateMongoClient ( c => c . SerializationDomain = customDomain ) ;
94+ var db = client . GetDatabase ( DriverTestConfiguration . DatabaseNamespace . DatabaseName ) ;
95+ var collection = db . GetCollection < Person > ( DriverTestConfiguration . CollectionNamespace . CollectionName ) ;
96+
97+ var retrievedTyped = collection . FindSync ( "{}" ) . ToList ( ) . Single ( ) ;
98+ Assert . Equal ( "Mario" , retrievedTyped . Name ) ;
99+ }
100+ }
101+
76102 public class Person
77103 {
78104 [ BsonId ] public ObjectId Id { get ; set ; }
79105 public string Name { get ; set ; }
80106 public int Age { get ; set ; }
81107 }
82108
109+ public class Person1
110+ {
111+ [ BsonId ] public ObjectId Id { get ; set ; }
112+ public string Name { get ; set ; }
113+ public int Age { get ; set ; }
114+ }
115+
83116 public class CustomStringSerializer : SealedClassSerializerBase < string > //This serializer just adds "test" to any serialised string
84117 {
85118 /// <inheritdoc/>
0 commit comments