@@ -134,9 +134,9 @@ public void TestExecuteTwice(bool ordered)
134
134
[ TestCase ( true , 1 ) ]
135
135
public void TestExecuteWithExplicitWriteConcern ( bool ordered , int w )
136
136
{
137
- var document = new BsonDocument ( "_id" , 1 ) ;
138
-
139
137
_collection . Drop ( ) ;
138
+
139
+ var document = new BsonDocument ( "_id" , 1 ) ;
140
140
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
141
141
bulk . Insert ( document ) ;
142
142
var result = bulk . Execute ( new WriteConcern { W = w } ) ;
@@ -153,6 +153,7 @@ public void TestExecuteWithExplicitWriteConcern(bool ordered, int w)
153
153
[ TestCase ( true ) ]
154
154
public void TestExecuteWithNoRequests ( bool ordered )
155
155
{
156
+ _collection . Drop ( ) ;
156
157
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
157
158
Assert . Throws < InvalidOperationException > ( ( ) => bulk . Execute ( ) ) ;
158
159
}
@@ -174,6 +175,7 @@ public void TestFindAfterExecute(bool ordered)
174
175
[ TestCase ( true ) ]
175
176
public void TestFindWithNullQuery ( bool ordered )
176
177
{
178
+ _collection . Drop ( ) ;
177
179
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
178
180
Assert . Throws < ArgumentNullException > ( ( ) => bulk . Find ( null ) ) ;
179
181
}
@@ -195,6 +197,7 @@ public void TestInsertAfterExecute(bool ordered)
195
197
[ TestCase ( true ) ]
196
198
public void TestInsertKeyValidation ( bool ordered )
197
199
{
200
+ _collection . Drop ( ) ;
198
201
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
199
202
bulk . Insert ( new BsonDocument ( "$key" , 1 ) ) ;
200
203
Assert . Throws < BsonSerializationException > ( ( ) => bulk . Execute ( ) ) ;
@@ -205,14 +208,15 @@ public void TestInsertKeyValidation(bool ordered)
205
208
[ TestCase ( true ) ]
206
209
public void TestInsertMultipleDocuments ( bool ordered )
207
210
{
211
+ _collection . Drop ( ) ;
212
+
208
213
var documents = new BsonDocument [ ]
209
214
{
210
215
new BsonDocument ( "_id" , 1 ) ,
211
216
new BsonDocument ( "_id" , 2 ) ,
212
217
new BsonDocument ( "_id" , 3 )
213
218
} ;
214
219
215
- _collection . Drop ( ) ;
216
220
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
217
221
bulk . Insert ( documents [ 0 ] ) ;
218
222
bulk . Insert ( documents [ 1 ] ) ;
@@ -230,9 +234,10 @@ public void TestInsertMultipleDocuments(bool ordered)
230
234
[ TestCase ( true ) ]
231
235
public void TestInsertOneDocument ( bool ordered )
232
236
{
237
+ _collection . Drop ( ) ;
238
+
233
239
var document = new BsonDocument ( "_id" , 1 ) ;
234
240
235
- _collection . Drop ( ) ;
236
241
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
237
242
bulk . Insert ( document ) ;
238
243
var result = bulk . Execute ( ) ;
@@ -284,15 +289,9 @@ public void TestMixedOperationsOrdered()
284
289
[ Test ]
285
290
public void TestMixedOperationsUnordered ( )
286
291
{
287
- var documents = new BsonDocument [ ]
288
- {
289
- new BsonDocument { { "a" , 1 } } ,
290
- new BsonDocument { { "a" , 2 } }
291
- } ;
292
-
293
292
_collection . Drop ( ) ;
294
- _collection . Insert ( documents [ 0 ] ) ;
295
- _collection . Insert ( documents [ 1 ] ) ;
293
+ _collection . Insert ( new BsonDocument { { "a" , 1 } } ) ;
294
+ _collection . Insert ( new BsonDocument { { "a" , 2 } } ) ;
296
295
297
296
var bulk = _collection . InitializeUnorderedBulkOperation ( ) ;
298
297
bulk . Find ( Query . EQ ( "a" , 1 ) ) . Update ( Update . Set ( "b" , 1 ) ) ;
@@ -331,6 +330,7 @@ public void TestMixedOperationsUnordered()
331
330
public void TestMixedUpsertsOrdered ( )
332
331
{
333
332
_collection . Drop ( ) ;
333
+
334
334
var bulk = _collection . InitializeOrderedBulkOperation ( ) ;
335
335
var id = ObjectId . GenerateNewId ( ) ;
336
336
bulk . Find ( Query . EQ ( "_id" , id ) ) . Upsert ( ) . UpdateOne ( Update . Set ( "y" , 1 ) ) ;
@@ -357,6 +357,7 @@ public void TestMixedUpsertsOrdered()
357
357
public void TestMixedUpsertsUnordered ( )
358
358
{
359
359
_collection . Drop ( ) ;
360
+
360
361
var bulk = _collection . InitializeUnorderedBulkOperation ( ) ;
361
362
bulk . Find ( Query . EQ ( "x" , 1 ) ) . Upsert ( ) . UpdateOne ( Update . Set ( "y" , 1 ) ) ;
362
363
bulk . Find ( Query . EQ ( "x" , 1 ) ) . RemoveOne ( ) ;
@@ -385,6 +386,7 @@ public void TestMixedUpsertsUnordered()
385
386
public void TestNoJournal ( bool ordered )
386
387
{
387
388
_collection . Drop ( ) ;
389
+
388
390
var documents = new [ ]
389
391
{
390
392
new BsonDocument ( "x" , 1 )
@@ -472,14 +474,14 @@ public void TestOrderedBatchWithErrors()
472
474
[ TestCase ( true ) ]
473
475
public void TestRemoveMultiple ( bool ordered )
474
476
{
477
+ _collection . Drop ( ) ;
478
+
475
479
var documents = new BsonDocument [ ]
476
480
{
477
481
new BsonDocument ( "_id" , 1 ) ,
478
482
new BsonDocument ( "_id" , 2 ) ,
479
483
new BsonDocument ( "_id" , 3 )
480
484
} ;
481
-
482
- _collection . Drop ( ) ;
483
485
_collection . Insert ( documents [ 0 ] ) ;
484
486
_collection . Insert ( documents [ 1 ] ) ;
485
487
_collection . Insert ( documents [ 2 ] ) ;
@@ -501,15 +503,9 @@ public void TestRemoveMultiple(bool ordered)
501
503
[ TestCase ( true ) ]
502
504
public void TestRemoveOneOnlyRemovesOneDocument ( bool ordered )
503
505
{
504
- var documents = new BsonDocument [ ]
505
- {
506
- new BsonDocument ( "key" , 1 ) ,
507
- new BsonDocument ( "key" , 1 )
508
- } ;
509
-
510
506
_collection . Drop ( ) ;
511
- _collection . Insert ( documents [ 0 ] ) ;
512
- _collection . Insert ( documents [ 1 ] ) ;
507
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
508
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
513
509
514
510
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
515
511
bulk . Find ( new QueryDocument ( ) ) . RemoveOne ( ) ;
@@ -527,15 +523,9 @@ public void TestRemoveOneOnlyRemovesOneDocument(bool ordered)
527
523
[ TestCase ( true ) ]
528
524
public void TestRemoveWithEmptyQueryRemovesAllDocuments ( bool ordered )
529
525
{
530
- var documents = new BsonDocument [ ]
531
- {
532
- new BsonDocument ( "key" , 1 ) ,
533
- new BsonDocument ( "key" , 1 )
534
- } ;
535
-
536
526
_collection . Drop ( ) ;
537
- _collection . Insert ( documents [ 0 ] ) ;
538
- _collection . Insert ( documents [ 1 ] ) ;
527
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
528
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
539
529
540
530
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
541
531
bulk . Find ( new QueryDocument ( ) ) . Remove ( ) ;
@@ -552,15 +542,9 @@ public void TestRemoveWithEmptyQueryRemovesAllDocuments(bool ordered)
552
542
[ TestCase ( true ) ]
553
543
public void TestRemoveWithQueryRemovesOnlyMatchingDocuments ( bool ordered )
554
544
{
555
- var documents = new BsonDocument [ ]
556
- {
557
- new BsonDocument ( "key" , 1 ) ,
558
- new BsonDocument ( "key" , 2 )
559
- } ;
560
-
561
545
_collection . Drop ( ) ;
562
- _collection . Insert ( documents [ 0 ] ) ;
563
- _collection . Insert ( documents [ 1 ] ) ;
546
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
547
+ _collection . Insert ( new BsonDocument ( "key" , 2 ) ) ;
564
548
565
549
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
566
550
bulk . Find ( Query . EQ ( "key" , 1 ) ) . Remove ( ) ;
@@ -581,6 +565,7 @@ public void TestReplaceOneKeyValidation(bool ordered)
581
565
{
582
566
_collection . Drop ( ) ;
583
567
_collection . Insert ( new BsonDocument ( "_id" , 1 ) ) ;
568
+
584
569
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
585
570
var query = Query . EQ ( "_id" , 1 ) ;
586
571
var replacement = new BsonDocument { { "_id" , 1 } , { "$key" , 1 } } ;
@@ -667,7 +652,6 @@ public void TestUnorderedBatchWithErrors()
667
652
new BsonDocument { { "b" , 3 } , { "a" , 2 } } ,
668
653
new BsonDocument { { "b" , 4 } , { "a" , 3 } }
669
654
} ;
670
-
671
655
Assert . That ( _collection . FindAll ( ) . SetFields ( Fields . Exclude ( "_id" ) ) , Is . EquivalentTo ( expectedDocuments ) ) ;
672
656
}
673
657
@@ -677,6 +661,7 @@ public void TestUnorderedBatchWithErrors()
677
661
[ TestCase ( true ) ]
678
662
public void TestUpdateChecksThatAllTopLevelFieldNamesAreOperators ( bool ordered )
679
663
{
664
+ _collection . Drop ( ) ;
680
665
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
681
666
var query = Query . EQ ( "_id" , 1 ) ;
682
667
var update = new UpdateDocument { { "key" , 1 } } ;
@@ -690,6 +675,7 @@ public void TestUpdateChecksThatAllTopLevelFieldNamesAreOperators(bool ordered)
690
675
[ TestCase ( true ) ]
691
676
public void TestUpdateKeyValidation ( bool ordered )
692
677
{
678
+ _collection . Drop ( ) ;
693
679
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
694
680
var query = Query . EQ ( "_id" , 1 ) ;
695
681
var update = Update . Set ( "$key" , 1 ) ;
@@ -702,15 +688,9 @@ public void TestUpdateKeyValidation(bool ordered)
702
688
[ TestCase ( true ) ]
703
689
public void TestUpdateOneBasic ( bool ordered )
704
690
{
705
- var documents = new BsonDocument [ ]
706
- {
707
- new BsonDocument ( "key" , 1 ) ,
708
- new BsonDocument ( "key" , 1 )
709
- } ;
710
-
711
691
_collection . Drop ( ) ;
712
- _collection . Insert ( documents [ 0 ] ) ;
713
- _collection . Insert ( documents [ 1 ] ) ;
692
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
693
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
714
694
715
695
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
716
696
bulk . Find ( new QueryDocument ( ) ) . UpdateOne ( Update . Set ( "key" , 3 ) ) ;
@@ -746,6 +726,7 @@ public void TestUpdateOneKeyValidation(bool ordered)
746
726
747
727
foreach ( var update in updates )
748
728
{
729
+ _collection . Drop ( ) ;
749
730
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
750
731
var query = Query . EQ ( "_id" , 1 ) ;
751
732
bulk . Find ( query ) . UpdateOne ( update ) ;
@@ -758,15 +739,9 @@ public void TestUpdateOneKeyValidation(bool ordered)
758
739
[ TestCase ( true ) ]
759
740
public void TestUpdateOnlyAffectsDocumentsThatMatch ( bool ordered )
760
741
{
761
- var documents = new BsonDocument [ ]
762
- {
763
- new BsonDocument ( "key" , 1 ) ,
764
- new BsonDocument ( "key" , 2 )
765
- } ;
766
-
767
742
_collection . Drop ( ) ;
768
- _collection . Insert ( documents [ 0 ] ) ;
769
- _collection . Insert ( documents [ 1 ] ) ;
743
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
744
+ _collection . Insert ( new BsonDocument ( "key" , 2 ) ) ;
770
745
771
746
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
772
747
bulk . Find ( Query . EQ ( "key" , 1 ) ) . Update ( Update . Set ( "x" , 1 ) ) ;
@@ -796,15 +771,9 @@ public void TestUpdateOnlyAffectsDocumentsThatMatch(bool ordered)
796
771
[ TestCase ( true ) ]
797
772
public void TestUpdateUpdatesAllMatchingDocuments ( bool ordered )
798
773
{
799
- var documents = new BsonDocument [ ]
800
- {
801
- new BsonDocument ( "key" , 1 ) ,
802
- new BsonDocument ( "key" , 2 )
803
- } ;
804
-
805
774
_collection . Drop ( ) ;
806
- _collection . Insert ( documents [ 0 ] ) ;
807
- _collection . Insert ( documents [ 1 ] ) ;
775
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
776
+ _collection . Insert ( new BsonDocument ( "key" , 2 ) ) ;
808
777
809
778
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
810
779
bulk . Find ( new QueryDocument ( ) ) . Update ( Update . Set ( "x" , 3 ) ) ;
@@ -832,9 +801,9 @@ public void TestUpdateUpdatesAllMatchingDocuments(bool ordered)
832
801
public void TestUpsertOneVeryLargeDocument ( bool ordered )
833
802
{
834
803
_collection . Drop ( ) ;
835
- var bigString = new string ( 'x' , 16 * 1024 * 1024 - 30 ) ;
836
804
837
805
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
806
+ var bigString = new string ( 'x' , 16 * 1024 * 1024 - 30 ) ;
838
807
bulk . Find ( Query . EQ ( "key" , 1 ) ) . Upsert ( ) . Update ( Update . Set ( "x" , bigString ) ) ;
839
808
var result = bulk . Execute ( ) ;
840
809
@@ -881,15 +850,9 @@ public void TestUpsertReplaceOneDoesNotAffectNonUpsertsInTheSameOperation(bool o
881
850
[ TestCase ( true ) ]
882
851
public void TestUpsertReplaceOneOnlyReplacesOneMatchingDocument ( bool ordered )
883
852
{
884
- var documents = new BsonDocument [ ]
885
- {
886
- new BsonDocument ( "key" , 1 ) ,
887
- new BsonDocument ( "key" , 1 )
888
- } ;
889
-
890
853
_collection . Drop ( ) ;
891
- _collection . Insert ( documents [ 0 ] ) ;
892
- _collection . Insert ( documents [ 1 ] ) ;
854
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
855
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
893
856
894
857
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
895
858
bulk . Find ( Query . EQ ( "key" , 1 ) ) . Upsert ( ) . ReplaceOne ( new BsonDocument ( "x" , 1 ) ) ;
@@ -956,15 +919,9 @@ public void TestUpsertUpdateOneDoesNotAffectNonUpsertsInTheSameOperation(bool or
956
919
[ TestCase ( true ) ]
957
920
public void TestUpsertUpdateOneOnlyAffectsOneMatchingDocument ( bool ordered )
958
921
{
959
- var documents = new BsonDocument [ ]
960
- {
961
- new BsonDocument ( "key" , 1 ) ,
962
- new BsonDocument ( "key" , 1 )
963
- } ;
964
-
965
922
_collection . Drop ( ) ;
966
- _collection . Insert ( documents [ 0 ] ) ;
967
- _collection . Insert ( documents [ 1 ] ) ;
923
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
924
+ _collection . Insert ( new BsonDocument ( "key" , 1 ) ) ;
968
925
969
926
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
970
927
bulk . Find ( Query . EQ ( "key" , 1 ) ) . Upsert ( ) . UpdateOne ( Update . Set ( "x" , 1 ) ) ;
@@ -1067,9 +1024,7 @@ public void TestUpsertWithNoMatchingDocument(bool ordered)
1067
1024
_collection . Insert ( new BsonDocument { { "_id" , id2 } , { "x" , 2 } } ) ;
1068
1025
1069
1026
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
1070
- var query = Query . EQ ( "_id" , id1 ) ;
1071
- var update = Update . Set ( "x" , 1 ) ;
1072
- bulk . Find ( query ) . Upsert ( ) . Update ( update ) ;
1027
+ bulk . Find ( Query . EQ ( "_id" , id1 ) ) . Upsert ( ) . Update ( Update . Set ( "x" , 1 ) ) ;
1073
1028
var result = bulk . Execute ( ) ;
1074
1029
1075
1030
var expectedResult = new ExpectedResult
@@ -1123,13 +1078,14 @@ public void TestUpsertWithOneMatchingDocument(bool ordered)
1123
1078
[ TestCase ( true ) ]
1124
1079
public void TestW0DoesNotReportErrors ( bool ordered )
1125
1080
{
1081
+ _collection . Drop ( ) ;
1082
+
1126
1083
var documents = new [ ]
1127
1084
{
1128
1085
new BsonDocument ( "_id" , 1 ) ,
1129
1086
new BsonDocument ( "_id" , 1 )
1130
1087
} ;
1131
1088
1132
- _collection . Drop ( ) ;
1133
1089
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
1134
1090
bulk . Insert ( documents [ 0 ] ) ;
1135
1091
bulk . Insert ( documents [ 1 ] ) ;
@@ -1150,6 +1106,7 @@ public void TestW2AgainstStandalone(bool ordered)
1150
1106
if ( _primary . InstanceType == MongoServerInstanceType . StandAlone )
1151
1107
{
1152
1108
_collection . Drop ( ) ;
1109
+
1153
1110
var documents = new [ ] { new BsonDocument ( "x" , 1 ) } ;
1154
1111
1155
1112
var bulk = InitializeBulkOperation ( _collection , ordered ) ;
0 commit comments