@@ -25,7 +25,7 @@ namespace MongoDB.Driver.Tests
25
25
public class MultipleRegistriesTests
26
26
{
27
27
[ Fact ]
28
- public void GeneralTest ( )
28
+ public void TestSerialization ( )
29
29
{
30
30
// At the moment having this uncommented would make the test fail due to the static caching of class maps
31
31
// {
@@ -73,13 +73,46 @@ public void GeneralTest()
73
73
}
74
74
}
75
75
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
+
76
102
public class Person
77
103
{
78
104
[ BsonId ] public ObjectId Id { get ; set ; }
79
105
public string Name { get ; set ; }
80
106
public int Age { get ; set ; }
81
107
}
82
108
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
+
83
116
public class CustomStringSerializer : SealedClassSerializerBase < string > //This serializer just adds "test" to any serialised string
84
117
{
85
118
/// <inheritdoc/>
0 commit comments