@@ -112,9 +112,11 @@ public void ConnectBadPassword()
112
112
}
113
113
114
114
[ Theory ]
115
- [ InlineData ( false ) ]
116
- [ InlineData ( true ) ]
117
- public void PersistSecurityInfo ( bool persistSecurityInfo )
115
+ [ InlineData ( false , false ) ]
116
+ [ InlineData ( true , false ) ]
117
+ [ InlineData ( false , true ) ]
118
+ [ InlineData ( true , true ) ]
119
+ public void PersistSecurityInfo ( bool persistSecurityInfo , bool closeConnection )
118
120
{
119
121
var csb = AppConfig . CreateConnectionStringBuilder ( ) ;
120
122
csb . PersistSecurityInfo = persistSecurityInfo ;
@@ -128,6 +130,15 @@ public void PersistSecurityInfo(bool persistSecurityInfo)
128
130
Assert . Equal ( csb . ConnectionString , connection . ConnectionString ) ;
129
131
else
130
132
Assert . Equal ( connectionStringWithoutPassword , connection . ConnectionString ) ;
133
+
134
+ if ( closeConnection )
135
+ {
136
+ connection . Close ( ) ;
137
+ if ( persistSecurityInfo )
138
+ Assert . Equal ( csb . ConnectionString , connection . ConnectionString ) ;
139
+ else
140
+ Assert . Equal ( connectionStringWithoutPassword , connection . ConnectionString ) ;
141
+ }
131
142
}
132
143
}
133
144
@@ -354,6 +365,46 @@ private static string QueryCurrentDatabase(MySqlConnection connection)
354
365
}
355
366
}
356
367
368
+ [ SkippableFact ( ConfigSettings . SecondaryDatabase ) ]
369
+ public void ChangeConnectionStringWhenOpen ( )
370
+ {
371
+ var csb = AppConfig . CreateConnectionStringBuilder ( ) ;
372
+ using ( var connection = new MySqlConnection ( csb . ConnectionString ) )
373
+ {
374
+ connection . Open ( ) ;
375
+ Assert . Equal ( csb . Database , connection . Database ) ;
376
+
377
+ csb . Database = AppConfig . SecondaryDatabase ;
378
+ #if BASELINE
379
+ Assert . Throws < MySqlException > ( ( ) =>
380
+ #else
381
+ Assert . Throws < InvalidOperationException > ( ( ) =>
382
+ #endif
383
+ {
384
+ connection . ConnectionString = csb . ConnectionString ;
385
+ } ) ;
386
+ }
387
+ }
388
+
389
+ [ SkippableFact ( ConfigSettings . SecondaryDatabase ) ]
390
+ public void ChangeConnectionStringAfterClose ( )
391
+ {
392
+ var csb = AppConfig . CreateConnectionStringBuilder ( ) ;
393
+ using ( var connection = new MySqlConnection ( csb . ConnectionString ) )
394
+ {
395
+ connection . Open ( ) ;
396
+ Assert . Equal ( csb . Database , connection . Database ) ;
397
+ connection . Close ( ) ;
398
+
399
+ csb . Database = AppConfig . SecondaryDatabase ;
400
+ connection . ConnectionString = csb . ConnectionString ;
401
+
402
+ connection . Open ( ) ;
403
+ Assert . Equal ( csb . Database , connection . Database ) ;
404
+ connection . Close ( ) ;
405
+ }
406
+ }
407
+
357
408
[ SkippableFact ( ServerFeatures . Sha256Password , ConfigSettings . RequiresSsl ) ]
358
409
public void Sha256WithSecureConnection( )
359
410
{
0 commit comments