@@ -247,7 +247,7 @@ public void WasUsed_should_call_serverSession()
247
247
248
248
Mock . Get ( subject . ServerSession ) . Verify ( m => m . WasUsed ( ) , Times . Once ) ;
249
249
}
250
-
250
+
251
251
[ Theory ]
252
252
[ ParameterAttributeData ]
253
253
public void EnsureTransactionsAreSupported_should_throw_when_there_are_no_connected_servers (
@@ -270,8 +270,6 @@ public void EnsureTransactionsAreSupported_should_throw_when_there_are_no_connec
270
270
[ Theory ]
271
271
[ InlineData ( "DU,CP" ) ]
272
272
[ InlineData ( "CP,DU" ) ]
273
- [ InlineData ( "DU,CR" ) ]
274
- [ InlineData ( "CR,DU" ) ]
275
273
public void EnsureTransactionsAreSupported_should_ignore_disconnected_servers ( string scenarios )
276
274
{
277
275
var clusterId = new ClusterId ( 1 ) ;
@@ -283,7 +281,7 @@ public void EnsureTransactionsAreSupported_should_ignore_disconnected_servers(st
283
281
var serverId = new ServerId ( clusterId , endPoint ) ;
284
282
var state = MapServerStateCode ( scenario [ 0 ] ) ;
285
283
var type = MapServerTypeCode ( scenario [ 1 ] ) ;
286
- var version = type == ServerType . ShardRouter ? Feature . ShardedTransactions . FirstSupportedVersion : Feature . Transactions . FirstSupportedVersion ;
284
+ var version = Feature . Transactions . FirstSupportedVersion ;
287
285
return CreateServerDescription ( serverId , endPoint , state , type , version ) ;
288
286
} )
289
287
. ToList ( ) ;
@@ -325,16 +323,15 @@ public void EnsureTransactionsAreSupported_should_throw_when_there_are_no_connec
325
323
}
326
324
327
325
[ Theory ]
328
- [ InlineData ( "PN" ) ]
329
- [ InlineData ( "PN,ST" ) ]
330
- [ InlineData ( "PT,SN" ) ]
331
- [ InlineData ( "RN" ) ]
332
- [ InlineData ( "RN,RT" ) ]
333
- [ InlineData ( "RT,RN" ) ]
334
- public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_bearing_server_does_not_support_transactions ( string scenarios )
326
+ [ InlineData ( "PN" , "Server version 3.6.99 does not support the Transactions feature." ) ]
327
+ [ InlineData ( "PN,ST" , "Server version 3.6.99 does not support the Transactions feature." ) ]
328
+ [ InlineData ( "PT,SN" , "Server version 3.6.99 does not support the Transactions feature." ) ]
329
+ [ InlineData ( "RN" , "Server version 3.6.99 does not support the Transactions feature." ) ]
330
+ [ InlineData ( "RN,RT" , "Server version 3.6.99 does not support the Transactions feature." ) ]
331
+ [ InlineData ( "RT,RN" , "This version of the driver does not support sharded transactions." ) ]
332
+ public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_bearing_server_does_not_support_transactions ( string scenarios , string expectedMessage )
335
333
{
336
334
var clusterId = new ClusterId ( 1 ) ;
337
- string unsupportedFeatureName = null ;
338
335
var servers =
339
336
SplitScenarios ( scenarios )
340
337
. Select ( ( scenario , i ) =>
@@ -343,12 +340,7 @@ public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_
343
340
var serverId = new ServerId ( clusterId , endPoint ) ;
344
341
var type = MapServerTypeCode ( scenario [ 0 ] ) ;
345
342
var supportsTransactions = MapSupportsTransactionsCode ( scenario [ 1 ] ) ;
346
- var feature = type == ServerType . ShardRouter ? Feature . ShardedTransactions : Feature . Transactions ;
347
- if ( ! supportsTransactions )
348
- {
349
- unsupportedFeatureName = feature . Name ;
350
- }
351
- var version = supportsTransactions ? feature . FirstSupportedVersion : feature . LastNotSupportedVersion ;
343
+ var version = supportsTransactions ? ( type == ServerType . ShardRouter ? new SemanticVersion ( 4 , 2 , 0 ) : Feature . Transactions . FirstSupportedVersion ) : Feature . Transactions . LastNotSupportedVersion ;
352
344
return CreateServerDescription ( serverId , endPoint , ServerState . Connected , type , version ) ;
353
345
} )
354
346
. ToList ( ) ;
@@ -358,7 +350,38 @@ public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_
358
350
var exception = Record . Exception ( ( ) => subject . EnsureTransactionsAreSupported ( ) ) ;
359
351
360
352
var e = exception . Should ( ) . BeOfType < NotSupportedException > ( ) . Subject ;
361
- e . Message . Should ( ) . Contain ( $ "does not support the { unsupportedFeatureName } feature.") ;
353
+ e . Message . Should ( ) . Contain ( expectedMessage ) ;
354
+ }
355
+
356
+ [ Theory ]
357
+ [ InlineData ( "3.6" , ServerType . ReplicaSetPrimary , "Server version 3.6.0 does not support the Transactions feature." ) ]
358
+ [ InlineData ( "4.0" , ServerType . ReplicaSetPrimary , null ) ]
359
+ [ InlineData ( "4.2" , ServerType . ReplicaSetPrimary , null ) ]
360
+ [ InlineData ( "3.6" , ServerType . ShardRouter , "Server version 3.6.0 does not support the Transactions feature." ) ]
361
+ [ InlineData ( "4.0" , ServerType . ShardRouter , "Server version 4.0.0 does not support the ShardedTransactions feature." ) ]
362
+ [ InlineData ( "4.2" , ServerType . ShardRouter , "This version of the driver does not support sharded transactions." ) ]
363
+ public void EnsureTransactionsAreSupported_should_have_expected_result_for_server_version_and_type ( string versionString , ServerType serverType , string expectedMessage )
364
+ {
365
+ var clusterId = new ClusterId ( 1 ) ;
366
+ var endPoint = new DnsEndPoint ( "localhost" , 27017 ) ;
367
+ var serverId = new ServerId ( clusterId , endPoint ) ;
368
+ var version = SemanticVersion . Parse ( versionString ) ;
369
+ var servers = new [ ] { CreateServerDescription ( serverId , endPoint , ServerState . Connected , serverType , version ) } ;
370
+ var clusterType = serverType == ServerType . ShardRouter ? ClusterType . Sharded : ClusterType . ReplicaSet ;
371
+ var clusterDescription = CreateClusterDescription ( clusterId : clusterId , connectionMode : ClusterConnectionMode . Automatic , type : clusterType , servers : servers ) ;
372
+ var subject = CreateSubject ( clusterDescription ) ;
373
+
374
+ var exception = Record . Exception ( ( ) => subject . EnsureTransactionsAreSupported ( ) ) ;
375
+
376
+ if ( expectedMessage == null )
377
+ {
378
+ exception . Should ( ) . BeNull ( ) ;
379
+ }
380
+ else
381
+ {
382
+ var e = exception . Should ( ) . BeOfType < NotSupportedException > ( ) . Subject ;
383
+ e . Message . Should ( ) . Contain ( expectedMessage ) ;
384
+ }
362
385
}
363
386
364
387
// private methods
0 commit comments