33
44namespace Simple . Data . Ado . Test
55{
6+ using System ;
7+
68 [ TestFixture ]
79 public class ConnectionModifierTest
810 {
@@ -24,6 +26,29 @@ public void ClearsConnection()
2426 Assert . IsNotInstanceOf < FooConnection > ( adapter . CreateConnection ( ) ) ;
2527 }
2628
29+ [ Test ]
30+ public void ConnectionCreatedEventFires ( )
31+ {
32+ bool fired = false ;
33+ EventHandler < ConnectionCreatedEventArgs > handler = ( o , e ) => { fired = true ; } ;
34+ AdoAdapter . ConnectionCreated += handler ;
35+ var adapter = new AdoAdapter ( new StubConnectionProvider ( ) ) ;
36+ var connection = adapter . CreateConnection ( ) ;
37+ AdoAdapter . ConnectionCreated -= handler ;
38+ Assert . True ( fired ) ;
39+ }
40+
41+ [ Test ]
42+ public void ConnectionCreatedCanOverrideConnection ( )
43+ {
44+ EventHandler < ConnectionCreatedEventArgs > handler = ( o , e ) => e . OverrideConnection ( new BarConnection ( e . Connection ) ) ;
45+ AdoAdapter . ConnectionCreated += handler ;
46+ var adapter = new AdoAdapter ( new StubConnectionProvider ( ) ) ;
47+ var connection = adapter . CreateConnection ( ) ;
48+ Assert . IsInstanceOf < BarConnection > ( connection ) ;
49+ AdoAdapter . ConnectionCreated -= handler ;
50+ }
51+
2752 private class FooConnection : IDbConnection
2853 {
2954 private readonly IDbConnection _wrapped ;
@@ -73,5 +98,55 @@ public void Open()
7398 public string Database { get ; private set ; }
7499 public ConnectionState State { get ; private set ; }
75100 }
101+
102+ private class BarConnection : IDbConnection
103+ {
104+ private readonly IDbConnection _wrapped ;
105+
106+ public BarConnection ( IDbConnection wrapped )
107+ {
108+ _wrapped = wrapped ;
109+ }
110+
111+ public void Dispose ( )
112+ {
113+ throw new System . NotImplementedException ( ) ;
114+ }
115+
116+ public IDbTransaction BeginTransaction ( )
117+ {
118+ throw new System . NotImplementedException ( ) ;
119+ }
120+
121+ public IDbTransaction BeginTransaction ( IsolationLevel il )
122+ {
123+ throw new System . NotImplementedException ( ) ;
124+ }
125+
126+ public void Close ( )
127+ {
128+ throw new System . NotImplementedException ( ) ;
129+ }
130+
131+ public void ChangeDatabase ( string databaseName )
132+ {
133+ throw new System . NotImplementedException ( ) ;
134+ }
135+
136+ public IDbCommand CreateCommand ( )
137+ {
138+ throw new System . NotImplementedException ( ) ;
139+ }
140+
141+ public void Open ( )
142+ {
143+ throw new System . NotImplementedException ( ) ;
144+ }
145+
146+ public string ConnectionString { get ; set ; }
147+ public int ConnectionTimeout { get ; private set ; }
148+ public string Database { get ; private set ; }
149+ public ConnectionState State { get ; private set ; }
150+ }
76151 }
77152}
0 commit comments