14
14
*/
15
15
16
16
using System ;
17
- using System . Collections . Generic ;
18
17
using System . Linq ;
19
18
using FluentAssertions ;
20
19
using MongoDB . Bson ;
21
20
using MongoDB . Bson . TestHelpers . XunitExtensions ;
22
- using MongoDB . Driver ;
23
21
using MongoDB . Driver . Builders ;
24
- using MongoDB . Driver . Core ;
25
22
using MongoDB . Driver . Core . Clusters ;
26
23
using MongoDB . Driver . Core . Misc ;
27
24
using MongoDB . Driver . Core . TestHelpers . XunitExtensions ;
25
+ using MongoDB . Driver . Legacy . Tests ;
26
+ using MongoDB . Driver . TestHelpers ;
28
27
using Xunit ;
29
28
30
29
namespace MongoDB . Driver . Tests . Operations
@@ -168,7 +167,7 @@ public void TestBatchSplittingUpdatesNearMaxWriteBatchCount(int maxBatchCountDel
168
167
{
169
168
var count = _primary . MaxBatchCount + maxBatchCountDelta ;
170
169
_collection . Drop ( ) ;
171
- _collection . InsertBatch ( Enumerable . Range ( 0 , count ) . Select ( n => new BsonDocument { { "_id" , n } , { "n" , 0 } } ) ) ;
170
+ _collection . InsertBatch ( Enumerable . Range ( 0 , count ) . Select ( n => new BsonDocument { { "_id" , n } , { "n" , 0 } } ) ) ;
172
171
173
172
var bulk = _collection . InitializeOrderedBulkOperation ( ) ;
174
173
for ( var n = 0 ; n < count ; n ++ )
@@ -209,21 +208,24 @@ public void TestExecuteTwice(bool ordered)
209
208
[ InlineData ( true , 1 ) ]
210
209
public void TestExecuteWithExplicitWriteConcern ( bool ordered , int w )
211
210
{
211
+ var server = LegacyTestConfiguration . GetServer ( retryWrites : false ) ;
212
+ var collection = GetCollection ( server ) ;
213
+
212
214
// use RequestStart because some of the test cases use { w : 0 }
213
- using ( _server . RequestStart ( ) )
215
+ using ( server . RequestStart ( ) )
214
216
{
215
- _collection . Drop ( ) ;
217
+ collection . Drop ( ) ;
216
218
217
219
var document = new BsonDocument ( "_id" , 1 ) ;
218
- var bulk = InitializeBulkOperation ( _collection , ordered ) ;
220
+ var bulk = InitializeBulkOperation ( collection , ordered ) ;
219
221
bulk . Insert ( document ) ;
220
222
var result = bulk . Execute ( new WriteConcern ( w ) ) ;
221
223
222
224
var expectedResult = new ExpectedResult { IsAcknowledged = w > 0 , InsertedCount = 1 } ;
223
225
CheckExpectedResult ( expectedResult , result ) ;
224
226
225
227
var expectedDocuments = new [ ] { document } ;
226
- _collection . FindAll ( ) . Should ( ) . BeEquivalentTo ( expectedDocuments ) ;
228
+ collection . FindAll ( ) . Should ( ) . BeEquivalentTo ( expectedDocuments ) ;
227
229
}
228
230
}
229
231
@@ -706,7 +708,7 @@ public void TestUnorderedBatchWithErrors()
706
708
707
709
var expectedDocuments = new BsonDocument [ ]
708
710
{
709
- new BsonDocument { { "b" , 1 } , { "a" , 1 } } ,
711
+ new BsonDocument { { "b" , 1 } , { "a" , 1 } } ,
710
712
_primary . BuildInfo . Version < new Version ( 2 , 6 , 0 ) ?
711
713
new BsonDocument { { "a" , 2 } , { "b" , 3 } } : // servers prior to 2.6 rewrite field order on update
712
714
new BsonDocument { { "b" , 3 } , { "a" , 2 } } ,
@@ -1127,18 +1129,21 @@ public void TestUpsertWithOneMatchingDocument(bool ordered)
1127
1129
[ InlineData ( true ) ]
1128
1130
public void TestW0DoesNotReportErrors ( bool ordered )
1129
1131
{
1132
+ var server = LegacyTestConfiguration . GetServer ( retryWrites : false ) ;
1133
+ var collection = GetCollection ( server ) ;
1134
+
1130
1135
// use a request so we can read our own writes even with older servers
1131
- using ( _server . RequestStart ( ) )
1136
+ using ( server . RequestStart ( ) )
1132
1137
{
1133
- _collection . Drop ( ) ;
1138
+ collection . Drop ( ) ;
1134
1139
1135
1140
var documents = new [ ]
1136
1141
{
1137
1142
new BsonDocument ( "_id" , 1 ) ,
1138
1143
new BsonDocument ( "_id" , 1 )
1139
1144
} ;
1140
1145
1141
- var bulk = InitializeBulkOperation ( _collection , ordered ) ;
1146
+ var bulk = InitializeBulkOperation ( collection , ordered ) ;
1142
1147
bulk . Insert ( documents [ 0 ] ) ;
1143
1148
bulk . Insert ( documents [ 1 ] ) ;
1144
1149
var result = bulk . Execute ( WriteConcern . Unacknowledged ) ;
@@ -1147,7 +1152,7 @@ public void TestW0DoesNotReportErrors(bool ordered)
1147
1152
CheckExpectedResult ( expectedResult , result ) ;
1148
1153
1149
1154
var expectedDocuments = new [ ] { documents [ 0 ] } ;
1150
- _collection . FindAll ( ) . Should ( ) . BeEquivalentTo ( expectedDocuments ) ;
1155
+ collection . FindAll ( ) . Should ( ) . BeEquivalentTo ( expectedDocuments ) ;
1151
1156
}
1152
1157
}
1153
1158
@@ -1252,6 +1257,13 @@ private void CheckExpectedResult(ExpectedResult expectedResult, BulkWriteResult<
1252
1257
}
1253
1258
}
1254
1259
1260
+ private MongoCollection < BsonDocument > GetCollection ( MongoServer server )
1261
+ {
1262
+ return server
1263
+ . GetDatabase ( CoreTestConfiguration . DatabaseNamespace . DatabaseName )
1264
+ . GetCollection ( GetType ( ) . Name ) ;
1265
+ }
1266
+
1255
1267
private BulkWriteOperation < T > InitializeBulkOperation < T > ( MongoCollection < T > collection , bool ordered )
1256
1268
{
1257
1269
return ordered ? collection . InitializeOrderedBulkOperation ( ) : collection . InitializeUnorderedBulkOperation ( ) ;
0 commit comments