@@ -247,7 +247,7 @@ public void WasUsed_should_call_serverSession()
247247
248248 Mock . Get ( subject . ServerSession ) . Verify ( m => m . WasUsed ( ) , Times . Once ) ;
249249 }
250-
250+
251251 [ Theory ]
252252 [ ParameterAttributeData ]
253253 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
270270 [ Theory ]
271271 [ InlineData ( "DU,CP" ) ]
272272 [ InlineData ( "CP,DU" ) ]
273- [ InlineData ( "DU,CR" ) ]
274- [ InlineData ( "CR,DU" ) ]
275273 public void EnsureTransactionsAreSupported_should_ignore_disconnected_servers ( string scenarios )
276274 {
277275 var clusterId = new ClusterId ( 1 ) ;
@@ -283,7 +281,7 @@ public void EnsureTransactionsAreSupported_should_ignore_disconnected_servers(st
283281 var serverId = new ServerId ( clusterId , endPoint ) ;
284282 var state = MapServerStateCode ( scenario [ 0 ] ) ;
285283 var type = MapServerTypeCode ( scenario [ 1 ] ) ;
286- var version = type == ServerType . ShardRouter ? Feature . ShardedTransactions . FirstSupportedVersion : Feature . Transactions . FirstSupportedVersion ;
284+ var version = Feature . Transactions . FirstSupportedVersion ;
287285 return CreateServerDescription ( serverId , endPoint , state , type , version ) ;
288286 } )
289287 . ToList ( ) ;
@@ -325,16 +323,15 @@ public void EnsureTransactionsAreSupported_should_throw_when_there_are_no_connec
325323 }
326324
327325 [ 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 )
335333 {
336334 var clusterId = new ClusterId ( 1 ) ;
337- string unsupportedFeatureName = null ;
338335 var servers =
339336 SplitScenarios ( scenarios )
340337 . Select ( ( scenario , i ) =>
@@ -343,12 +340,7 @@ public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_
343340 var serverId = new ServerId ( clusterId , endPoint ) ;
344341 var type = MapServerTypeCode ( scenario [ 0 ] ) ;
345342 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 ;
352344 return CreateServerDescription ( serverId , endPoint , ServerState . Connected , type , version ) ;
353345 } )
354346 . ToList ( ) ;
@@ -358,7 +350,38 @@ public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_
358350 var exception = Record . Exception ( ( ) => subject . EnsureTransactionsAreSupported ( ) ) ;
359351
360352 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+ }
362385 }
363386
364387 // private methods
0 commit comments