Skip to content

Commit 6204c3e

Browse files
committed
Fixed tests
1 parent 48ba1a3 commit 6204c3e

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

tests/MongoDB.Driver.Tests/MultipleRegistriesTests.cs

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public void TestSerialization()
3636
{
3737
RequireServer.Check();
3838

39+
// The first section demonstrates that the class maps are also separated
3940
{
4041
var client = CreateClient();
4142
var collection = GetTypedCollection<Person>(client);
@@ -52,10 +53,9 @@ public void TestSerialization()
5253
Assert.Equal(expectedVal, toString);
5354
}
5455

55-
//The first section demonstrates that the class maps are also separated
5656
{
5757
var customDomain = BsonSerializer.CreateSerializationDomain();
58-
customDomain.RegisterSerializer(new CustomStringSerializer());
58+
customDomain.RegisterSerializer(new CustomStringSerializer("test1"));
5959

6060
var client = CreateClientWithDomain(customDomain);
6161
var collection = GetTypedCollection<Person>(client);
@@ -68,12 +68,71 @@ public void TestSerialization()
6868
var toString = retrievedAsBson.ToString();
6969

7070
var expectedVal =
71-
$$"""{ "_id" : { "$oid" : "{{_defaultObjectIdString}}" }, "Name" : "Mariotest", "Age" : 24 }""";
71+
$$"""{ "_id" : { "$oid" : "{{_defaultObjectIdString}}" }, "Name" : "Mariotest1", "Age" : 24 }""";
7272
Assert.Equal(expectedVal, toString);
7373

7474
var retrievedTyped = collection.FindSync(FilterDefinition<Person>.Empty).ToList().Single();
7575
Assert.Equal("Mario", retrievedTyped.Name);
7676
}
77+
78+
{
79+
var customDomain = BsonSerializer.CreateSerializationDomain();
80+
customDomain.RegisterSerializer(new CustomStringSerializer("test2"));
81+
82+
var client = CreateClientWithDomain(customDomain);
83+
var collection = GetTypedCollection<Person>(client);
84+
var bsonCollection = GetUntypedCollection(client);
85+
86+
var person = new Person { Id = _defaultId, Name = "Mario", Age = 24 };
87+
collection.InsertOne(person);
88+
89+
var retrievedAsBson = bsonCollection.FindSync(FilterDefinition<BsonDocument>.Empty).ToList().Single();
90+
var toString = retrievedAsBson.ToString();
91+
92+
var expectedVal =
93+
$$"""{ "_id" : { "$oid" : "{{_defaultObjectIdString}}" }, "Name" : "Mariotest2", "Age" : 24 }""";
94+
Assert.Equal(expectedVal, toString);
95+
96+
var retrievedTyped = collection.FindSync(FilterDefinition<Person>.Empty).ToList().Single();
97+
Assert.Equal("Mario", retrievedTyped.Name);
98+
}
99+
}
100+
101+
[Fact]
102+
public void TestMultipleDomainSimultaneously()
103+
{
104+
RequireServer.Check();
105+
106+
var objectId1 = ObjectId.GenerateNewId();
107+
var objectId2 = ObjectId.GenerateNewId();
108+
109+
var client = CreateClient();
110+
var collection = GetTypedCollection<Person>(client);
111+
var bsonCollection = GetUntypedCollection(client);
112+
113+
var customDomain = BsonSerializer.CreateSerializationDomain();
114+
customDomain.RegisterSerializer(new CustomStringSerializer("test1"));
115+
var client2 = CreateClientWithDomain(customDomain);
116+
var collection2 = GetTypedCollection<Person>(client2);
117+
var bsonCollection2 = GetUntypedCollection(client2);
118+
119+
var person = new Person { Id = objectId1, Name = "Mario", Age = 24 };
120+
var person2 = new Person { Id = objectId2, Name = "Mario", Age = 24 };
121+
collection.InsertOne(person);
122+
collection2.InsertOne(person2);
123+
124+
var retrieved = bsonCollection.FindSync(Builders<BsonDocument>.Filter.Eq("_id", objectId1)).ToList().Single();
125+
var expectedVal =
126+
$$"""{ "_id" : { "$oid" : "{{objectId1.ToString()}}" }, "Name" : "Mario", "Age" : 24 }""";
127+
Assert.Equal(expectedVal, retrieved.ToString());
128+
129+
var retrievedAsBson = bsonCollection2.FindSync(Builders<BsonDocument>.Filter.Eq("_id", objectId2)).ToList().Single();
130+
var expectedVal2 =
131+
$$"""{ "_id" : { "$oid" : "{{objectId2.ToString()}}" }, "Name" : "Mariotest1", "Age" : 24 }""";
132+
Assert.Equal(expectedVal2, retrievedAsBson.ToString());
133+
134+
var retrievedTyped = collection2.FindSync(p => p.Id == objectId2).ToList().Single();
135+
Assert.Equal("Mario", retrievedTyped.Name);
77136
}
78137

79138
[Fact]
@@ -155,7 +214,7 @@ public void TestConventions()
155214
var toString = retrievedAsBson.ToString();
156215

157216
var expectedVal =
158-
$$"""{ "_id" : { "$oid" : "{{_defaultObjectIdString}}" }, "Name" : "Mario", "Age" : 24 }""";
217+
$$"""{ "_id" : { "$oid" : "{{_defaultObjectIdString}}" }, "name" : "Mario", "Age" : 24 }""";
159218
Assert.Equal(expectedVal, toString);
160219
}
161220

0 commit comments

Comments
 (0)