@@ -374,6 +374,10 @@ public void When_nothing_is_specified(string connectionString)
374
374
subject. MaxPoolSize . Should ( ) . Be ( null ) ;
375
375
subject. MinPoolSize . Should ( ) . Be ( null ) ;
376
376
subject. Password . Should ( ) . BeNull ( ) ;
377
+ subject. ProxyHost . Should ( ) . Be ( null ) ;
378
+ subject. ProxyPort . Should ( ) . Be ( null ) ;
379
+ subject. ProxyPassword . Should ( ) . Be ( null ) ;
380
+ subject. ProxyUsername . Should ( ) . Be ( null ) ;
377
381
subject. ReadConcernLevel . Should ( ) . BeNull ( ) ;
378
382
subject. ReadPreference . Should ( ) . BeNull ( ) ;
379
383
subject. ReadPreferenceTags . Should ( ) . BeNull ( ) ;
@@ -420,6 +424,10 @@ public void When_everything_is_specified()
420
424
"maxLifeTime=5ms;" +
421
425
"maxPoolSize=20;" +
422
426
"minPoolSize=15;" +
427
+ "proxyHost=host.com;" +
428
+ "proxyPort=2020;" +
429
+ "proxyUsername=user;" +
430
+ "proxyPassword=passw;" +
423
431
"readConcernLevel=majority;" +
424
432
"readPreference=primary;" +
425
433
"readPreferenceTags=dc:1;" +
@@ -462,6 +470,10 @@ public void When_everything_is_specified()
462
470
subject . MaxPoolSize . Should ( ) . Be ( 20 ) ;
463
471
subject . MinPoolSize . Should ( ) . Be ( 15 ) ;
464
472
subject . Password . Should ( ) . Be ( "pass" ) ;
473
+ subject . ProxyHost . Should ( ) . Be ( "host.com" ) ;
474
+ subject . ProxyPort . Should ( ) . Be ( 2020 ) ;
475
+ subject . ProxyUsername . Should ( ) . Be ( "user" ) ;
476
+ subject . ProxyPassword . Should ( ) . Be ( "passw" ) ;
465
477
subject . ReadConcernLevel . Should ( ) . Be ( ReadConcernLevel . Majority ) ;
466
478
subject . ReadPreference . Should ( ) . Be ( ReadPreferenceMode . Primary ) ;
467
479
subject . ReadPreferenceTags . Single ( ) . Should ( ) . Be ( new TagSet ( new [ ] { new Tag ( "dc" , "1" ) } ) ) ;
@@ -1200,6 +1212,46 @@ public void When_srvServiceName_is_specified_without_a_srv_scheme()
1200
1212
exception. Message . Should ( ) . Contain ( "srvServiceName" ) ;
1201
1213
}
1202
1214
1215
+ [ Theory ]
1216
+ [ InlineData ( "mongodb://localhost?proxyHost=222.222.222.12" , "222.222.222.12" , null , null , null ) ]
1217
+ [ InlineData ( "mongodb://localhost?proxyHost=222.222.222.12&proxyPort=8080" , "222.222.222.12" , 8080 , null , null ) ]
1218
+ [ InlineData ( "mongodb://localhost?proxyHost=example.com" , "example.com" , null , null , null ) ]
1219
+ [ InlineData ( "mongodb://localhost?proxyHost=example.com&proxyPort=8080" , "example.com" , 8080 , null , null ) ]
1220
+ [ InlineData ( "mongodb://localhost?proxyHost=example.com&proxyUsername=user&proxyPassword=passw" , "example.com" , null , "user" , "passw" ) ]
1221
+ [ InlineData ( "mongodb://localhost?proxyHost=example.com&proxyPort=8080&proxyUsername=user&proxyPassword=passw" , "example.com" , 8080 , "user" , "passw" ) ]
1222
+ public void When_proxy_parameters_are_specified( string connectionString , string host , int ? port , string username , string password )
1223
+ {
1224
+ var subject = new ConnectionString( connectionString ) ;
1225
+
1226
+ subject. ProxyHost . Should ( ) . Be ( host ) ;
1227
+ subject. ProxyPort . Should ( ) . Be ( port ) ;
1228
+ subject. ProxyUsername . Should ( ) . Be ( username ) ;
1229
+ subject. ProxyPassword . Should ( ) . Be ( password ) ;
1230
+ }
1231
+
1232
+ [ Theory ]
1233
+ [ InlineData ( "mongodb://localhost?proxyPort=2020" , "proxyPort" ) ]
1234
+ [ InlineData ( "mongodb://localhost?proxyUsername=user" , "proxyUsername" ) ]
1235
+ [ InlineData ( "mongodb://localhost?proxyPassword=pasw" , "proxyPassword" ) ]
1236
+ public void When_proxyParameter_is_specified_without_proxyHost( string connectionString , string parameterName )
1237
+ {
1238
+ var exception = Record. Exception ( ( ) => new ConnectionString ( connectionString ) ) ;
1239
+
1240
+ exception. Should ( ) . BeOfType < MongoConfigurationException > ( ) ;
1241
+ exception. Message . Should ( ) . Contain ( parameterName ) ;
1242
+ }
1243
+
1244
+ [ Theory ]
1245
+ [ InlineData ( "mongodb://localhost?proxyHost=host.com&proxyUsername=user" ) ]
1246
+ [ InlineData ( "mongodb://localhost?proxyHost=host.com&proxyPassword=pasw" ) ]
1247
+ public void When_proxyPassword_and_proxyUsername_are_not_specified_together( string connectionString )
1248
+ {
1249
+ var exception = Record. Exception ( ( ) => new ConnectionString ( connectionString ) ) ;
1250
+
1251
+ exception. Should ( ) . BeOfType < MongoConfigurationException > ( ) ;
1252
+ exception. Message . Should ( ) . Contain ( "proxyUsername and proxyPassword" ) ;
1253
+ }
1254
+
1203
1255
[ Theory ]
1204
1256
[ ParameterAttributeData ]
1205
1257
public void Valid_srvMaxHosts_with_mongodbsrv_scheme_should_be_valid( [ Values ( 0 , 42 ) ] int srvMaxHosts)
0 commit comments