Skip to content

Commit b4f5beb

Browse files
committed
address pr comments
1 parent 978799e commit b4f5beb

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

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

+37-21
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,11 @@ public async Task MongoClient_bulkWrite_unacknowledged_write_concern_uses_w0_all
617617
documentCount.Should().Be(numModels);
618618
}
619619

620+
// https://specifications.readthedocs.io/en/latest/crud/tests/#16-generated-document-identifiers-are-the-first-field-in-their-document
621+
// The next three consecutive tests defined below are part of the prose test linked above.
620622
[Theory]
621623
[ParameterAttributeData]
622-
public async Task Ensure_generated_ids_are_first_fields_in_document([Values(true, false)] bool async)
624+
public async Task Ensure_generated_ids_are_first_fields_in_document_using_insertOne([Values(true, false)] bool async)
623625
{
624626
var eventCapturer = new EventCapturer().Capture<CommandStartedEvent>();
625627
var client = CreateMongoClient(eventCapturer);
@@ -635,13 +637,21 @@ public async Task Ensure_generated_ids_are_first_fields_in_document([Values(true
635637
testCollection.InsertOne(document);
636638
}
637639

638-
eventCapturer.Next();
640+
eventCapturer.Next(); // skip the hello command that is captured.
639641
eventCapturer.Next().Should().BeOfType<CommandStartedEvent>()
640642
.Subject.Command["documents"][0].AsBsonDocument.Names.First().Should().Be("_id");
641643
document.Names.Should().Contain("_id");
644+
}
645+
646+
[Theory]
647+
[ParameterAttributeData]
648+
public async Task Ensure_generated_ids_are_first_fields_in_document_using_collection_bulkWrite([Values(true, false)] bool async)
649+
{
650+
var eventCapturer = new EventCapturer().Capture<CommandStartedEvent>();
651+
var client = CreateMongoClient(eventCapturer);
652+
var testCollection = client.GetDatabase("test").GetCollection<BsonDocument>("test");
642653

643-
eventCapturer.Clear();
644-
document = new BsonDocument("x", 2);
654+
var document = new BsonDocument("x", 1);
645655
if (async)
646656
{
647657
await testCollection.BulkWriteAsync([new InsertOneModel<BsonDocument>(document)]);
@@ -651,29 +661,35 @@ public async Task Ensure_generated_ids_are_first_fields_in_document([Values(true
651661
testCollection.BulkWrite([new InsertOneModel<BsonDocument>(document)]);
652662
}
653663

654-
eventCapturer.Count.Should().Be(1);
664+
eventCapturer.Next(); // skip the hello command that is captured.
655665
eventCapturer.Next().Should().BeOfType<CommandStartedEvent>()
656666
.Subject.Command["documents"][0].AsBsonDocument.Names.First().Should().Be("_id");
657667
document.Names.Should().Contain("_id");
668+
}
658669

659-
if (Feature.ClientBulkWrite.IsSupported(CoreTestConfiguration.MaxWireVersion))
660-
{
661-
eventCapturer.Clear();
662-
document = new BsonDocument("x", 3);
663-
if (async)
664-
{
665-
await client.BulkWriteAsync([new BulkWriteInsertOneModel<BsonDocument>("test.test", document)]);
666-
}
667-
else
668-
{
669-
client.BulkWrite([new BulkWriteInsertOneModel<BsonDocument>("test.test", document)]);
670-
}
670+
[Theory]
671+
[ParameterAttributeData]
672+
public async Task Ensure_generated_ids_are_first_fields_in_document_using_client_bulkWrite([Values(true, false)] bool async)
673+
{
674+
RequireServer.Check().Supports(Feature.ClientBulkWrite).Serverless(false);
675+
676+
var eventCapturer = new EventCapturer().Capture<CommandStartedEvent>();
677+
var client = CreateMongoClient(eventCapturer);
671678

672-
eventCapturer.Count.Should().Be(1);
673-
eventCapturer.Next().Should().BeOfType<CommandStartedEvent>()
674-
.Subject.Command["ops"][0]["document"].AsBsonDocument.Names.First().Should().Be("_id");
675-
document.Names.Should().Contain("_id");
679+
var document = new BsonDocument("x", 1);
680+
if (async)
681+
{
682+
await client.BulkWriteAsync([new BulkWriteInsertOneModel<BsonDocument>("test.test", document)]);
683+
}
684+
else
685+
{
686+
client.BulkWrite([new BulkWriteInsertOneModel<BsonDocument>("test.test", document)]);
676687
}
688+
689+
eventCapturer.Next(); // skip the hello command that is captured.
690+
eventCapturer.Next().Should().BeOfType<CommandStartedEvent>()
691+
.Subject.Command["ops"][0]["document"].AsBsonDocument.Names.First().Should().Be("_id");
692+
document.Names.Should().Contain("_id");
677693
}
678694

679695
// private methods

0 commit comments

Comments
 (0)