@@ -617,9 +617,11 @@ public async Task MongoClient_bulkWrite_unacknowledged_write_concern_uses_w0_all
617
617
documentCount . Should ( ) . Be ( numModels ) ;
618
618
}
619
619
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.
620
622
[ Theory ]
621
623
[ 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 )
623
625
{
624
626
var eventCapturer = new EventCapturer ( ) . Capture < CommandStartedEvent > ( ) ;
625
627
var client = CreateMongoClient ( eventCapturer ) ;
@@ -635,13 +637,21 @@ public async Task Ensure_generated_ids_are_first_fields_in_document([Values(true
635
637
testCollection . InsertOne ( document ) ;
636
638
}
637
639
638
- eventCapturer . Next ( ) ;
640
+ eventCapturer . Next ( ) ; // skip the hello command that is captured.
639
641
eventCapturer . Next ( ) . Should ( ) . BeOfType < CommandStartedEvent > ( )
640
642
. Subject . Command [ "documents" ] [ 0 ] . AsBsonDocument . Names . First ( ) . Should ( ) . Be ( "_id" ) ;
641
643
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" ) ;
642
653
643
- eventCapturer . Clear ( ) ;
644
- document = new BsonDocument ( "x" , 2 ) ;
654
+ var document = new BsonDocument( "x" , 1 ) ;
645
655
if ( async)
646
656
{
647
657
await testCollection . BulkWriteAsync ( [ new InsertOneModel < BsonDocument > ( document ) ] ) ;
@@ -651,29 +661,35 @@ public async Task Ensure_generated_ids_are_first_fields_in_document([Values(true
651
661
testCollection . BulkWrite ( [ new InsertOneModel < BsonDocument > ( document ) ] ) ;
652
662
}
653
663
654
- eventCapturer . Count . Should ( ) . Be ( 1 ) ;
664
+ eventCapturer . Next ( ) ; // skip the hello command that is captured.
655
665
eventCapturer . Next ( ) . Should ( ) . BeOfType < CommandStartedEvent > ( )
656
666
. Subject . Command [ "documents" ] [ 0 ] . AsBsonDocument . Names . First ( ) . Should ( ) . Be ( "_id" ) ;
657
667
document. Names . Should ( ) . Contain ( "_id" ) ;
668
+ }
658
669
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 ) ;
671
678
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 ) ] ) ;
676
687
}
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" ) ;
677
693
}
678
694
679
695
// private methods
0 commit comments