Skip to content

Commit a672a75

Browse files
author
rstam
committed
CSHARP-694: Change values in unit tests to use values that fail in the same way in Mono as in .NET.
1 parent 849a640 commit a672a75

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

MongoDB.DriverUnitTests/MongoCollectionTests.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,16 +1109,14 @@ public void TestLenientRead()
11091109

11101110
var document = new BsonDocument { { "_id", ObjectId.GenerateNewId() }, { "x", "abc" } };
11111111
var bson = document.ToBson();
1112-
bson[28] = 0xed; // replace "abc" with 0xeda0db which is not valid UTF8
1113-
bson[29] = 0xa0;
1114-
bson[30] = 0xdb;
1112+
bson[28] = 0xc0; // replace 'a' with invalid lone first code point (not followed by 10xxxxxx)
11151113

11161114
// use a RawBsonDocument to sneak the invalid bytes into the database
11171115
var rawBsonDocument = new RawBsonDocument(bson);
11181116
collection.Insert(rawBsonDocument);
11191117

11201118
var rehydrated = collection.FindOne(Query.EQ("_id", document["_id"]));
1121-
Assert.AreEqual("\ufffd\ufffd", rehydrated["x"].AsString);
1119+
Assert.AreEqual("\ufffd" + "bc", rehydrated["x"].AsString);
11221120
}
11231121

11241122
[Test]
@@ -1127,7 +1125,7 @@ public void TestLenientWrite()
11271125
var settings = new MongoCollectionSettings { WriteEncoding = new UTF8Encoding(false, false) };
11281126
var collection = _database.GetCollection(Configuration.TestCollection.Name, settings);
11291127

1130-
var document = new BsonDocument("x", "\ud83d");
1128+
var document = new BsonDocument("x", "\udc00"); // invalid lone low surrogate
11311129
collection.Save(document);
11321130

11331131
var rehydrated = collection.FindOne(Query.EQ("_id", document["_id"]));
@@ -1495,9 +1493,7 @@ public void TestStrictRead()
14951493

14961494
var document = new BsonDocument { { "_id", ObjectId.GenerateNewId() }, { "x", "abc" } };
14971495
var bson = document.ToBson();
1498-
bson[28] = 0xed; // replace "abc" with 0xeda0db which is not valid UTF8
1499-
bson[29] = 0xa0;
1500-
bson[30] = 0xdb;
1496+
bson[28] = 0xc0; // replace 'a' with invalid lone first code point (not followed by 10xxxxxx)
15011497

15021498
// use a RawBsonDocument to sneak the invalid bytes into the database
15031499
var rawBsonDocument = new RawBsonDocument(bson);
@@ -1512,7 +1508,7 @@ public void TestStrictWrite()
15121508
var settings = new MongoCollectionSettings { WriteEncoding = new UTF8Encoding(false, true) };
15131509
var collection = _database.GetCollection(Configuration.TestCollection.Name, settings);
15141510

1515-
var document = new BsonDocument("x", "\ud83d");
1511+
var document = new BsonDocument("x", "\udc00"); // invalid lone low surrogate
15161512
Assert.Throws<EncoderFallbackException>(() => { collection.Insert(document); });
15171513
}
15181514

0 commit comments

Comments
 (0)