25
25
using MongoDB . Driver . Core . Clusters ;
26
26
using MongoDB . Driver . Core . Compression ;
27
27
using MongoDB . Driver . Core . Configuration ;
28
+ using MongoDB . Driver . Core . Connections ;
28
29
using MongoDB . Driver . Core . Servers ;
29
30
using MongoDB . Driver . Core . TestHelpers . XunitExtensions ;
30
31
using MongoDB . Driver . Encryption ;
@@ -233,6 +234,8 @@ public void TestConnectTimeout()
233
234
Assert . Throws < InvalidOperationException > ( ( ) => { settings . ConnectTimeout = connectTimeout ; } ) ;
234
235
}
235
236
237
+ //TODO I understand we want to keep tests in alphabetical order, but I think it would make sense to group them by scope
238
+ //Tests like this, that should be modified for every new setting added (for instance) should be at the top of this test suite.
236
239
[ Fact ]
237
240
public void TestDefaults ( )
238
241
{
@@ -266,6 +269,7 @@ public void TestDefaults()
266
269
Assert . Equal ( ServerMonitoringMode . Auto , settings . ServerMonitoringMode ) ;
267
270
Assert . Equal ( MongoDefaults . ServerSelectionTimeout , settings . ServerSelectionTimeout ) ;
268
271
Assert . Equal ( MongoDefaults . SocketTimeout , settings . SocketTimeout ) ;
272
+ Assert . Equal ( null , settings . Socks5ProxySettings ) ;
269
273
Assert . Null ( settings . SslSettings ) ;
270
274
#pragma warning disable 618
271
275
Assert . Equal ( false , settings . UseSsl ) ;
@@ -435,6 +439,10 @@ public void TestEquals()
435
439
clone . SocketTimeout = new TimeSpan ( 1 , 2 , 3 ) ;
436
440
Assert . False ( clone . Equals ( settings ) ) ;
437
441
442
+ clone = settings . Clone ( ) ;
443
+ clone . Socks5ProxySettings = Socks5ProxySettings . Create ( "host.com" , null , null , null ) ;
444
+ Assert . False ( clone . Equals ( settings ) ) ;
445
+
438
446
clone = settings . Clone ( ) ;
439
447
clone . SslSettings = new SslSettings { CheckCertificateRevocation = false } ;
440
448
Assert . False ( clone . Equals ( settings ) ) ;
@@ -475,6 +483,7 @@ public void TestEquals()
475
483
settings . ReadConcern = ReadConcern . Majority ;
476
484
settings . ReadEncoding = new UTF8Encoding ( false , false ) ;
477
485
settings . ServerApi = new ServerApi ( ServerApiVersion . V1 ) ;
486
+ settings . Socks5ProxySettings = Socks5ProxySettings . Create ( "host.com" , 8080 , null , null ) ;
478
487
settings . WriteConcern = WriteConcern . W2 ;
479
488
settings . WriteEncoding = new UTF8Encoding ( false , false ) ;
480
489
@@ -485,6 +494,7 @@ public void TestEquals()
485
494
clone . ReadEncoding = new UTF8Encoding ( false , false ) ;
486
495
clone . ReadPreference = clone . ReadPreference . With ( settings . ReadPreference . ReadPreferenceMode ) ;
487
496
clone . ServerApi = new ServerApi ( settings . ServerApi . Version ) ;
497
+ clone . Socks5ProxySettings = Socks5ProxySettings . Create ( "host.com" , 8080 , null , null ) ;
488
498
clone . WriteConcern = WriteConcern . FromBsonDocument ( settings . WriteConcern . ToBsonDocument ( ) ) ;
489
499
clone . WriteEncoding = new UTF8Encoding ( false , false ) ;
490
500
@@ -582,7 +592,8 @@ public void TestFromUrl()
582
592
"maxConnecting=3;maxIdleTime=124;maxLifeTime=125;maxPoolSize=126;minPoolSize=127;readConcernLevel=majority;" +
583
593
"readPreference=secondary;readPreferenceTags=a:1,b:2;readPreferenceTags=c:3,d:4;retryReads=false;retryWrites=true;socketTimeout=129;" +
584
594
"serverMonitoringMode=Stream;serverSelectionTimeout=20s;tls=true;sslVerifyCertificate=false;waitqueuesize=130;waitQueueTimeout=131;" +
585
- "w=1;fsync=true;journal=true;w=2;wtimeout=131;gssapiServiceName=other" ;
595
+ "w=1;fsync=true;journal=true;w=2;wtimeout=131;gssapiServiceName=other" +
596
+ "&proxyHost=host.com&proxyPort=2020&proxyUsername=user&proxyPassword=passw" ;
586
597
var builder = new MongoUrlBuilder ( connectionString ) ;
587
598
var url = builder . ToMongoUrl ( ) ;
588
599
@@ -620,6 +631,10 @@ public void TestFromUrl()
620
631
Assert . Equal ( ServerMonitoringMode . Stream , settings . ServerMonitoringMode ) ;
621
632
Assert . Equal ( url . ServerSelectionTimeout , settings . ServerSelectionTimeout ) ;
622
633
Assert . Equal ( url . SocketTimeout , settings . SocketTimeout ) ;
634
+ Assert . Equal ( url . ProxyHost , settings . Socks5ProxySettings . Host ) ;
635
+ Assert . Equal ( url . ProxyPort , settings . Socks5ProxySettings . Port ) ;
636
+ Assert . Equal ( url . ProxyUsername , ( ( Socks5AuthenticationSettings . UsernamePasswordAuthenticationSettings ) settings . Socks5ProxySettings . Authentication ) . Username ) ;
637
+ Assert . Equal ( url . ProxyPassword , ( ( Socks5AuthenticationSettings . UsernamePasswordAuthenticationSettings ) settings . Socks5ProxySettings . Authentication ) . Password ) ;
623
638
#pragma warning disable 618
624
639
Assert . Equal ( url . TlsDisableCertificateRevocationCheck , ! settings . SslSettings . CheckCertificateRevocation ) ;
625
640
Assert . Equal ( url . UseSsl , settings . UseSsl ) ;
@@ -1175,6 +1190,21 @@ public void TestSocketTimeout()
1175
1190
Assert . Throws < InvalidOperationException > ( ( ) => { settings . SocketTimeout = socketTimeout ; } ) ;
1176
1191
}
1177
1192
1193
+ [ Fact ]
1194
+ public void TestSocks5ProxySettings ( )
1195
+ {
1196
+ var settings = new MongoClientSettings ( ) ;
1197
+ Assert . Equal ( null , settings . Socks5ProxySettings ) ;
1198
+
1199
+ var newProxySettings = Socks5ProxySettings . Create ( "host.com" , 280 , "test" , "test" ) ;
1200
+ settings . Socks5ProxySettings = newProxySettings ;
1201
+ Assert . Equal ( newProxySettings , settings . Socks5ProxySettings ) ;
1202
+
1203
+ settings . Freeze ( ) ;
1204
+ Assert . Equal ( newProxySettings , settings . Socks5ProxySettings ) ;
1205
+ Assert . Throws < InvalidOperationException > ( ( ) => { settings . Socks5ProxySettings = newProxySettings ; } ) ;
1206
+ }
1207
+
1178
1208
[ Fact ]
1179
1209
public void TestSslSettings ( )
1180
1210
{
@@ -1326,6 +1356,7 @@ public void ToClusterKey_should_copy_relevant_values()
1326
1356
ServerMonitoringMode = ServerMonitoringMode . Poll ,
1327
1357
ServerSelectionTimeout = TimeSpan . FromSeconds ( 6 ) ,
1328
1358
SocketTimeout = TimeSpan . FromSeconds ( 4 ) ,
1359
+ Socks5ProxySettings = Socks5ProxySettings . Create ( "host" , 2020 , null , null ) ,
1329
1360
SslSettings = sslSettings ,
1330
1361
UseTls = true ,
1331
1362
#pragma warning disable 618
@@ -1362,6 +1393,7 @@ public void ToClusterKey_should_copy_relevant_values()
1362
1393
result . ServerMonitoringMode . Should ( ) . Be ( ServerMonitoringMode . Poll ) ;
1363
1394
result . ServerSelectionTimeout . Should ( ) . Be ( subject . ServerSelectionTimeout ) ;
1364
1395
result . SocketTimeout . Should ( ) . Be ( subject . SocketTimeout ) ;
1396
+ result . Socks5ProxySettings . Should ( ) . Be ( subject . Socks5ProxySettings ) ;
1365
1397
result . SslSettings . Should ( ) . Be ( subject . SslSettings ) ;
1366
1398
result . UseTls . Should ( ) . Be ( subject . UseTls ) ;
1367
1399
#pragma warning disable 618
0 commit comments