@@ -617,6 +617,65 @@ public async Task MongoClient_bulkWrite_unacknowledged_write_concern_uses_w0_all
617
617
documentCount . Should ( ) . Be ( numModels ) ;
618
618
}
619
619
620
+ [ Theory ]
621
+ [ ParameterAttributeData ]
622
+ public async Task Ensure_generated_ids_are_first_fields_in_document ( [ Values ( true , false ) ] bool async )
623
+ {
624
+ var eventCapturer = new EventCapturer ( ) . Capture < CommandStartedEvent > ( ) ;
625
+ var client = CreateMongoClient ( eventCapturer ) ;
626
+ var testCollection = client . GetDatabase ( "test" ) . GetCollection < BsonDocument > ( "test" ) ;
627
+
628
+ var document = new BsonDocument ( "x" , 1 ) ;
629
+ if ( async)
630
+ {
631
+ await testCollection . InsertOneAsync ( document ) ;
632
+ }
633
+ else
634
+ {
635
+ testCollection . InsertOne ( document ) ;
636
+ }
637
+
638
+ eventCapturer . Next ( ) ;
639
+ eventCapturer . Next ( ) . Should ( ) . BeOfType < CommandStartedEvent > ( )
640
+ . Subject . Command [ "documents" ] [ 0 ] . AsBsonDocument . Names . First ( ) . Should ( ) . Be ( "_id" ) ;
641
+ document . Names . Should ( ) . Contain ( "_id" ) ;
642
+
643
+ eventCapturer . Clear ( ) ;
644
+ document = new BsonDocument ( "x" , 2 ) ;
645
+ if ( async)
646
+ {
647
+ await testCollection . BulkWriteAsync ( [ new InsertOneModel < BsonDocument > ( document ) ] ) ;
648
+ }
649
+ else
650
+ {
651
+ testCollection . BulkWrite ( [ new InsertOneModel < BsonDocument > ( document ) ] ) ;
652
+ }
653
+
654
+ eventCapturer . Count . Should ( ) . Be ( 1 ) ;
655
+ eventCapturer . Next ( ) . Should ( ) . BeOfType < CommandStartedEvent > ( )
656
+ . Subject . Command [ "documents" ] [ 0 ] . AsBsonDocument . Names . First ( ) . Should ( ) . Be ( "_id" ) ;
657
+ document . Names . Should ( ) . Contain ( "_id" ) ;
658
+
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
+ }
671
+
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" ) ;
676
+ }
677
+ }
678
+
620
679
// private methods
621
680
private FailPoint ConfigureFailPoint ( string failpointCommand )
622
681
{
0 commit comments