@@ -134,9 +134,9 @@ public void TestExecuteTwice(bool ordered)
134134 [ TestCase ( true , 1 ) ]
135135 public void TestExecuteWithExplicitWriteConcern ( bool ordered , int w )
136136 {
137- var document = new BsonDocument ( "_id" , 1 ) ;
138-
139137 _collection . Drop ( ) ;
138+
139+ var document = new BsonDocument ( "_id" , 1 ) ;
140140 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
141141 bulk . Insert ( document ) ;
142142 var result = bulk . Execute ( new WriteConcern { W = w } ) ;
@@ -153,6 +153,7 @@ public void TestExecuteWithExplicitWriteConcern(bool ordered, int w)
153153 [ TestCase ( true ) ]
154154 public void TestExecuteWithNoRequests ( bool ordered )
155155 {
156+ _collection . Drop ( ) ;
156157 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
157158 Assert . Throws < InvalidOperationException > ( ( ) => bulk . Execute ( ) ) ;
158159 }
@@ -174,6 +175,7 @@ public void TestFindAfterExecute(bool ordered)
174175 [ TestCase ( true ) ]
175176 public void TestFindWithNullQuery ( bool ordered )
176177 {
178+ _collection . Drop ( ) ;
177179 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
178180 Assert . Throws < ArgumentNullException > ( ( ) => bulk . Find ( null ) ) ;
179181 }
@@ -195,6 +197,7 @@ public void TestInsertAfterExecute(bool ordered)
195197 [ TestCase ( true ) ]
196198 public void TestInsertKeyValidation ( bool ordered )
197199 {
200+ _collection . Drop ( ) ;
198201 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
199202 bulk . Insert ( new BsonDocument ( "$key" , 1 ) ) ;
200203 Assert . Throws < BsonSerializationException > ( ( ) => bulk . Execute ( ) ) ;
@@ -205,14 +208,15 @@ public void TestInsertKeyValidation(bool ordered)
205208 [ TestCase ( true ) ]
206209 public void TestInsertMultipleDocuments ( bool ordered )
207210 {
211+ _collection . Drop ( ) ;
212+
208213 var documents = new BsonDocument [ ]
209214 {
210215 new BsonDocument ( "_id" , 1 ) ,
211216 new BsonDocument ( "_id" , 2 ) ,
212217 new BsonDocument ( "_id" , 3 )
213218 } ;
214219
215- _collection . Drop ( ) ;
216220 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
217221 bulk . Insert ( documents [ 0 ] ) ;
218222 bulk . Insert ( documents [ 1 ] ) ;
@@ -230,9 +234,10 @@ public void TestInsertMultipleDocuments(bool ordered)
230234 [ TestCase ( true ) ]
231235 public void TestInsertOneDocument ( bool ordered )
232236 {
237+ _collection . Drop ( ) ;
238+
233239 var document = new BsonDocument ( "_id" , 1 ) ;
234240
235- _collection . Drop ( ) ;
236241 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
237242 bulk . Insert ( document ) ;
238243 var result = bulk . Execute ( ) ;
@@ -284,15 +289,9 @@ public void TestMixedOperationsOrdered()
284289 [ Test ]
285290 public void TestMixedOperationsUnordered ( )
286291 {
287- var documents = new BsonDocument [ ]
288- {
289- new BsonDocument { { "a" , 1 } } ,
290- new BsonDocument { { "a" , 2 } }
291- } ;
292-
293292 _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 } } ) ;
296295
297296 var bulk = _collection . InitializeUnorderedBulkOperation ( ) ;
298297 bulk . Find ( Query . EQ ( "a" , 1 ) ) . Update ( Update . Set ( "b" , 1 ) ) ;
@@ -331,6 +330,7 @@ public void TestMixedOperationsUnordered()
331330 public void TestMixedUpsertsOrdered ( )
332331 {
333332 _collection . Drop ( ) ;
333+
334334 var bulk = _collection . InitializeOrderedBulkOperation ( ) ;
335335 var id = ObjectId . GenerateNewId ( ) ;
336336 bulk . Find ( Query . EQ ( "_id" , id ) ) . Upsert ( ) . UpdateOne ( Update . Set ( "y" , 1 ) ) ;
@@ -357,6 +357,7 @@ public void TestMixedUpsertsOrdered()
357357 public void TestMixedUpsertsUnordered ( )
358358 {
359359 _collection . Drop ( ) ;
360+
360361 var bulk = _collection . InitializeUnorderedBulkOperation ( ) ;
361362 bulk . Find ( Query . EQ ( "x" , 1 ) ) . Upsert ( ) . UpdateOne ( Update . Set ( "y" , 1 ) ) ;
362363 bulk . Find ( Query . EQ ( "x" , 1 ) ) . RemoveOne ( ) ;
@@ -385,6 +386,7 @@ public void TestMixedUpsertsUnordered()
385386 public void TestNoJournal ( bool ordered )
386387 {
387388 _collection . Drop ( ) ;
389+
388390 var documents = new [ ]
389391 {
390392 new BsonDocument ( "x" , 1 )
@@ -472,14 +474,14 @@ public void TestOrderedBatchWithErrors()
472474 [ TestCase ( true ) ]
473475 public void TestRemoveMultiple ( bool ordered )
474476 {
477+ _collection . Drop ( ) ;
478+
475479 var documents = new BsonDocument [ ]
476480 {
477481 new BsonDocument ( "_id" , 1 ) ,
478482 new BsonDocument ( "_id" , 2 ) ,
479483 new BsonDocument ( "_id" , 3 )
480484 } ;
481-
482- _collection . Drop ( ) ;
483485 _collection . Insert ( documents [ 0 ] ) ;
484486 _collection . Insert ( documents [ 1 ] ) ;
485487 _collection . Insert ( documents [ 2 ] ) ;
@@ -501,15 +503,9 @@ public void TestRemoveMultiple(bool ordered)
501503 [ TestCase ( true ) ]
502504 public void TestRemoveOneOnlyRemovesOneDocument ( bool ordered )
503505 {
504- var documents = new BsonDocument [ ]
505- {
506- new BsonDocument ( "key" , 1 ) ,
507- new BsonDocument ( "key" , 1 )
508- } ;
509-
510506 _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 ) ) ;
513509
514510 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
515511 bulk . Find ( new QueryDocument ( ) ) . RemoveOne ( ) ;
@@ -527,15 +523,9 @@ public void TestRemoveOneOnlyRemovesOneDocument(bool ordered)
527523 [ TestCase ( true ) ]
528524 public void TestRemoveWithEmptyQueryRemovesAllDocuments ( bool ordered )
529525 {
530- var documents = new BsonDocument [ ]
531- {
532- new BsonDocument ( "key" , 1 ) ,
533- new BsonDocument ( "key" , 1 )
534- } ;
535-
536526 _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 ) ) ;
539529
540530 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
541531 bulk . Find ( new QueryDocument ( ) ) . Remove ( ) ;
@@ -552,15 +542,9 @@ public void TestRemoveWithEmptyQueryRemovesAllDocuments(bool ordered)
552542 [ TestCase ( true ) ]
553543 public void TestRemoveWithQueryRemovesOnlyMatchingDocuments ( bool ordered )
554544 {
555- var documents = new BsonDocument [ ]
556- {
557- new BsonDocument ( "key" , 1 ) ,
558- new BsonDocument ( "key" , 2 )
559- } ;
560-
561545 _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 ) ) ;
564548
565549 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
566550 bulk . Find ( Query . EQ ( "key" , 1 ) ) . Remove ( ) ;
@@ -581,6 +565,7 @@ public void TestReplaceOneKeyValidation(bool ordered)
581565 {
582566 _collection . Drop ( ) ;
583567 _collection . Insert ( new BsonDocument ( "_id" , 1 ) ) ;
568+
584569 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
585570 var query = Query . EQ ( "_id" , 1 ) ;
586571 var replacement = new BsonDocument { { "_id" , 1 } , { "$key" , 1 } } ;
@@ -667,7 +652,6 @@ public void TestUnorderedBatchWithErrors()
667652 new BsonDocument { { "b" , 3 } , { "a" , 2 } } ,
668653 new BsonDocument { { "b" , 4 } , { "a" , 3 } }
669654 } ;
670-
671655 Assert . That ( _collection . FindAll ( ) . SetFields ( Fields . Exclude ( "_id" ) ) , Is . EquivalentTo ( expectedDocuments ) ) ;
672656 }
673657
@@ -677,6 +661,7 @@ public void TestUnorderedBatchWithErrors()
677661 [ TestCase ( true ) ]
678662 public void TestUpdateChecksThatAllTopLevelFieldNamesAreOperators ( bool ordered )
679663 {
664+ _collection . Drop ( ) ;
680665 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
681666 var query = Query . EQ ( "_id" , 1 ) ;
682667 var update = new UpdateDocument { { "key" , 1 } } ;
@@ -690,6 +675,7 @@ public void TestUpdateChecksThatAllTopLevelFieldNamesAreOperators(bool ordered)
690675 [ TestCase ( true ) ]
691676 public void TestUpdateKeyValidation ( bool ordered )
692677 {
678+ _collection . Drop ( ) ;
693679 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
694680 var query = Query . EQ ( "_id" , 1 ) ;
695681 var update = Update . Set ( "$key" , 1 ) ;
@@ -702,15 +688,9 @@ public void TestUpdateKeyValidation(bool ordered)
702688 [ TestCase ( true ) ]
703689 public void TestUpdateOneBasic ( bool ordered )
704690 {
705- var documents = new BsonDocument [ ]
706- {
707- new BsonDocument ( "key" , 1 ) ,
708- new BsonDocument ( "key" , 1 )
709- } ;
710-
711691 _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 ) ) ;
714694
715695 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
716696 bulk . Find ( new QueryDocument ( ) ) . UpdateOne ( Update . Set ( "key" , 3 ) ) ;
@@ -746,6 +726,7 @@ public void TestUpdateOneKeyValidation(bool ordered)
746726
747727 foreach ( var update in updates )
748728 {
729+ _collection . Drop ( ) ;
749730 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
750731 var query = Query . EQ ( "_id" , 1 ) ;
751732 bulk . Find ( query ) . UpdateOne ( update ) ;
@@ -758,15 +739,9 @@ public void TestUpdateOneKeyValidation(bool ordered)
758739 [ TestCase ( true ) ]
759740 public void TestUpdateOnlyAffectsDocumentsThatMatch ( bool ordered )
760741 {
761- var documents = new BsonDocument [ ]
762- {
763- new BsonDocument ( "key" , 1 ) ,
764- new BsonDocument ( "key" , 2 )
765- } ;
766-
767742 _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 ) ) ;
770745
771746 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
772747 bulk . Find ( Query . EQ ( "key" , 1 ) ) . Update ( Update . Set ( "x" , 1 ) ) ;
@@ -796,15 +771,9 @@ public void TestUpdateOnlyAffectsDocumentsThatMatch(bool ordered)
796771 [ TestCase ( true ) ]
797772 public void TestUpdateUpdatesAllMatchingDocuments ( bool ordered )
798773 {
799- var documents = new BsonDocument [ ]
800- {
801- new BsonDocument ( "key" , 1 ) ,
802- new BsonDocument ( "key" , 2 )
803- } ;
804-
805774 _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 ) ) ;
808777
809778 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
810779 bulk . Find ( new QueryDocument ( ) ) . Update ( Update . Set ( "x" , 3 ) ) ;
@@ -832,9 +801,9 @@ public void TestUpdateUpdatesAllMatchingDocuments(bool ordered)
832801 public void TestUpsertOneVeryLargeDocument ( bool ordered )
833802 {
834803 _collection . Drop ( ) ;
835- var bigString = new string ( 'x' , 16 * 1024 * 1024 - 30 ) ;
836804
837805 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
806+ var bigString = new string ( 'x' , 16 * 1024 * 1024 - 30 ) ;
838807 bulk . Find ( Query . EQ ( "key" , 1 ) ) . Upsert ( ) . Update ( Update . Set ( "x" , bigString ) ) ;
839808 var result = bulk . Execute ( ) ;
840809
@@ -881,15 +850,9 @@ public void TestUpsertReplaceOneDoesNotAffectNonUpsertsInTheSameOperation(bool o
881850 [ TestCase ( true ) ]
882851 public void TestUpsertReplaceOneOnlyReplacesOneMatchingDocument ( bool ordered )
883852 {
884- var documents = new BsonDocument [ ]
885- {
886- new BsonDocument ( "key" , 1 ) ,
887- new BsonDocument ( "key" , 1 )
888- } ;
889-
890853 _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 ) ) ;
893856
894857 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
895858 bulk . Find ( Query . EQ ( "key" , 1 ) ) . Upsert ( ) . ReplaceOne ( new BsonDocument ( "x" , 1 ) ) ;
@@ -956,15 +919,9 @@ public void TestUpsertUpdateOneDoesNotAffectNonUpsertsInTheSameOperation(bool or
956919 [ TestCase ( true ) ]
957920 public void TestUpsertUpdateOneOnlyAffectsOneMatchingDocument ( bool ordered )
958921 {
959- var documents = new BsonDocument [ ]
960- {
961- new BsonDocument ( "key" , 1 ) ,
962- new BsonDocument ( "key" , 1 )
963- } ;
964-
965922 _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 ) ) ;
968925
969926 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
970927 bulk . Find ( Query . EQ ( "key" , 1 ) ) . Upsert ( ) . UpdateOne ( Update . Set ( "x" , 1 ) ) ;
@@ -1067,9 +1024,7 @@ public void TestUpsertWithNoMatchingDocument(bool ordered)
10671024 _collection . Insert ( new BsonDocument { { "_id" , id2 } , { "x" , 2 } } ) ;
10681025
10691026 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 ) ) ;
10731028 var result = bulk . Execute ( ) ;
10741029
10751030 var expectedResult = new ExpectedResult
@@ -1123,13 +1078,14 @@ public void TestUpsertWithOneMatchingDocument(bool ordered)
11231078 [ TestCase ( true ) ]
11241079 public void TestW0DoesNotReportErrors ( bool ordered )
11251080 {
1081+ _collection . Drop ( ) ;
1082+
11261083 var documents = new [ ]
11271084 {
11281085 new BsonDocument ( "_id" , 1 ) ,
11291086 new BsonDocument ( "_id" , 1 )
11301087 } ;
11311088
1132- _collection . Drop ( ) ;
11331089 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
11341090 bulk . Insert ( documents [ 0 ] ) ;
11351091 bulk . Insert ( documents [ 1 ] ) ;
@@ -1150,6 +1106,7 @@ public void TestW2AgainstStandalone(bool ordered)
11501106 if ( _primary . InstanceType == MongoServerInstanceType . StandAlone )
11511107 {
11521108 _collection . Drop ( ) ;
1109+
11531110 var documents = new [ ] { new BsonDocument ( "x" , 1 ) } ;
11541111
11551112 var bulk = InitializeBulkOperation ( _collection , ordered ) ;
0 commit comments