File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
src/MySqlConnector/MySql.Data.MySqlClient Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1616namespace MySql . Data . MySqlClient
1717{
1818 public sealed class MySqlConnection : DbConnection
19+ #if ! NETSTANDARD1_3
20+ , ICloneable
21+ #endif
1922 {
2023 public MySqlConnection ( )
2124 : this ( default )
@@ -438,6 +441,12 @@ public override async ValueTask DisposeAsync()
438441 }
439442 }
440443
444+ public MySqlConnection Clone ( ) => new MySqlConnection ( m_connectionString ) ;
445+
446+ #if ! NETSTANDARD1_3
447+ object ICloneable . Clone ( ) => Clone ( ) ;
448+ #endif
449+
441450 internal ServerSession Session
442451 {
443452 get
Original file line number Diff line number Diff line change 11using System ;
2+ using System . Data ;
23using Dapper ;
34using MySql . Data . MySqlClient ;
45using Xunit ;
@@ -141,5 +142,25 @@ public void ConnectionTimeoutExplicitValueAfterOpen()
141142 connection . Open ( ) ;
142143 Assert . Equal ( 30 , connection . ConnectionTimeout ) ;
143144 }
145+
146+ [ Fact ]
147+ public void CloneClonesConnectionString ( )
148+ {
149+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
150+ using var connection2 = ( MySqlConnection ) connection . Clone ( ) ;
151+ Assert . Equal ( connection . ConnectionString , connection2 . ConnectionString ) ;
152+ #if ! BASELINE
153+ Assert . Equal ( AppConfig . ConnectionString , connection2 . ConnectionString ) ;
154+ #endif
155+ }
156+
157+ [ Fact ]
158+ public void CloneIsClosed ( )
159+ {
160+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
161+ connection . Open ( ) ;
162+ using var connection2 = ( MySqlConnection ) connection . Clone ( ) ;
163+ Assert . Equal ( ConnectionState . Closed , connection2 . State ) ;
164+ }
144165 }
145166}
You can’t perform that action at this time.
0 commit comments