Skip to content

Commit db2c2f7

Browse files
authored
CSHARP-5582: Assert unset BulkWriteException.partialResult in CRUD prose tests (#1727)
1 parent d07e5ac commit db2c2f7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/MongoDB.Driver/Core/Operations/ClientBulkWriteOperation.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ private void EnsureCanProceedNextBatch(ConnectionId connectionId, BulkWriteRawRe
210210
{
211211
if (bulkWriteResult.TopLevelException != null)
212212
{
213-
var partialResult = ToClientBulkWriteResult(bulkWriteResult);
213+
ClientBulkWriteResult partialResult = null;
214+
if (_writeModels.Offset != 0)
215+
{
216+
partialResult = ToClientBulkWriteResult(bulkWriteResult);
217+
}
218+
214219
throw new ClientBulkWriteException(
215220
connectionId,
216221
"An error occurred during bulkWrite operation. See InnerException for more details.",

tests/MongoDB.Driver.Tests/Specifications/crud/prose-tests/CrudProseTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ public async Task MongoClient_bulkWrite_throws_if_no_operations_can_be_added_big
496496

497497
var bulkWriteException = exception.Should().BeOfType<ClientBulkWriteException>().Subject;
498498
bulkWriteException.InnerException.Should().BeOfType<FormatException>();
499+
bulkWriteException.PartialResult.Should().BeNull();
499500
}
500501

501502
// https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L602
@@ -522,6 +523,7 @@ public async Task MongoClient_bulkWrite_throws_if_no_operations_can_be_added_big
522523

523524
var bulkWriteException = exception.Should().BeOfType<ClientBulkWriteException>().Subject;
524525
bulkWriteException.InnerException.Should().BeOfType<FormatException>();
526+
bulkWriteException.PartialResult.Should().BeNull();
525527
}
526528

527529
// https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L647
@@ -560,6 +562,7 @@ public async Task MongoClient_bulkWrite_throws_if_auto_encryption_configured([Va
560562
: Record.Exception(() => client.BulkWrite(models));
561563

562564
exception.Should().BeOfType<NotSupportedException>();
565+
exception.Message.Should().Be("BulkWrite does not currently support automatic encryption.");
563566
}
564567

565568
// https://github.com/mongodb/specifications/blob/d1bdb68b7b4aec9681ea56d41c8b9a6c1a97d365/source/crud/tests/README.md?plain=1#L699

0 commit comments

Comments
 (0)