@@ -26,73 +26,74 @@ public class FirebirdClientDriverFixtureAsync
26
26
private string _connectionString ;
27
27
private FirebirdClientDriver _driver ;
28
28
29
+ [ OneTimeSetUp ]
30
+ public void OneTimeSetup ( )
31
+ {
32
+ var cfg = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
33
+
34
+ var dlct = cfg . GetProperty ( "dialect" ) ;
35
+ if ( ! dlct . Contains ( "Firebird" ) )
36
+ Assert . Ignore ( "Applies only to Firebird" ) ;
37
+
38
+ _driver = new FirebirdClientDriver ( ) ;
39
+ _driver . Configure ( cfg . Properties ) ;
40
+ _connectionString = cfg . GetProperty ( "connection.connection_string" ) ;
41
+ }
42
+
29
43
[ Test ]
30
44
public async Task ConnectionPooling_OpenThenCloseThenOpenAnotherOne_OnlyOneConnectionIsPooledAsync ( )
31
45
{
32
- MakeDriver ( ) ;
33
-
34
46
_driver . ClearPool ( _connectionString ) ;
35
47
36
48
var allreadyEstablished = await ( GetEstablishedConnectionsAsync ( ) ) ;
37
49
38
- var connection1 = MakeConnection ( ) ;
39
- var connection2 = MakeConnection ( ) ;
40
-
41
- //open first connection
42
- await ( connection1 . OpenAsync ( ) ) ;
43
- await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After first open" ) ) ;
50
+ using ( var connection1 = MakeConnection ( ) )
51
+ using ( var connection2 = MakeConnection ( ) )
52
+ {
53
+ //open first connection
54
+ await ( connection1 . OpenAsync ( ) ) ;
55
+ await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After first open" ) ) ;
44
56
45
- //return it to the pool
46
- connection1 . Close ( ) ;
47
- await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After first close" ) ) ;
57
+ //return it to the pool
58
+ connection1 . Close ( ) ;
59
+ await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After first close" ) ) ;
48
60
49
- //open the second connection
50
- await ( connection2 . OpenAsync ( ) ) ;
51
- await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After second open" ) ) ;
61
+ //open the second connection
62
+ await ( connection2 . OpenAsync ( ) ) ;
63
+ await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After second open" ) ) ;
52
64
53
- //return it to the pool
54
- connection2 . Close ( ) ;
55
- await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After second close" ) ) ;
65
+ //return it to the pool
66
+ connection2 . Close ( ) ;
67
+ await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After second close" ) ) ;
68
+ }
56
69
}
57
70
58
71
[ Test ]
59
72
public async Task ConnectionPooling_OpenThenCloseTwoAtTheSameTime_TowConnectionsArePooledAsync ( )
60
73
{
61
- MakeDriver ( ) ;
62
-
63
74
_driver . ClearPool ( _connectionString ) ;
64
75
65
76
var allreadyEstablished = await ( GetEstablishedConnectionsAsync ( ) ) ;
66
77
67
- var connection1 = MakeConnection ( ) ;
68
- var connection2 = MakeConnection ( ) ;
69
-
70
- //open first connection
71
- await ( connection1 . OpenAsync ( ) ) ;
72
- await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After first open" ) ) ;
73
-
74
- //open second one
75
- await ( connection2 . OpenAsync ( ) ) ;
76
- await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 2 , "After second open" ) ) ;
77
-
78
- //return connection1 to the pool
79
- connection1 . Close ( ) ;
80
- await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 2 , "After first close" ) ) ;
78
+ using ( var connection1 = MakeConnection ( ) )
79
+ using ( var connection2 = MakeConnection ( ) )
80
+ {
81
+ //open first connection
82
+ await ( connection1 . OpenAsync ( ) ) ;
83
+ await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 1 , "After first open" ) ) ;
81
84
82
- //return connection2 to the pool
83
- connection2 . Close ( ) ;
84
- await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 2 , "After second close" ) ) ;
85
- }
85
+ //open second one
86
+ await ( connection2 . OpenAsync ( ) ) ;
87
+ await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 2 , "After second open" ) ) ;
86
88
87
- private void MakeDriver ( )
88
- {
89
- var cfg = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
90
- var dlct = cfg . GetProperty ( "dialect" ) ;
91
- if ( ! dlct . Contains ( "Firebird" ) )
92
- Assert . Ignore ( "Applies only to Firebird" ) ;
89
+ //return connection1 to the pool
90
+ connection1 . Close ( ) ;
91
+ await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 2 , "After first close" ) ) ;
93
92
94
- _driver = new FirebirdClientDriver ( ) ;
95
- _connectionString = cfg . GetProperty ( "connection.connection_string" ) ;
93
+ //return connection2 to the pool
94
+ connection2 . Close ( ) ;
95
+ await ( VerifyCountOfEstablishedConnectionsIsAsync ( allreadyEstablished + 2 , "After second close" ) ) ;
96
+ }
96
97
}
97
98
98
99
private DbConnection MakeConnection ( )
@@ -125,38 +126,38 @@ private DbConnection MakeConnection()
125
126
private DbCommand BuildSelectCaseCommand ( SqlType paramType )
126
127
{
127
128
var sqlString = new SqlStringBuilder ( )
128
- . Add ( "select (case when col = " )
129
- . AddParameter ( )
130
- . Add ( " then " )
131
- . AddParameter ( )
132
- . Add ( " else " )
133
- . AddParameter ( )
134
- . Add ( " end) from table" )
135
- . ToSqlString ( ) ;
129
+ . Add ( "select (case when col = " )
130
+ . AddParameter ( )
131
+ . Add ( " then " )
132
+ . AddParameter ( )
133
+ . Add ( " else " )
134
+ . AddParameter ( )
135
+ . Add ( " end) from table" )
136
+ . ToSqlString ( ) ;
136
137
137
138
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType , paramType , paramType } ) ;
138
139
}
139
140
140
141
private DbCommand BuildSelectConcatCommand ( SqlType paramType )
141
142
{
142
143
var sqlString = new SqlStringBuilder ( )
143
- . Add ( "select col || " )
144
- . AddParameter ( )
145
- . Add ( " || " )
146
- . Add ( "col " )
147
- . Add ( "from table" )
148
- . ToSqlString ( ) ;
144
+ . Add ( "select col || " )
145
+ . AddParameter ( )
146
+ . Add ( " || " )
147
+ . Add ( "col " )
148
+ . Add ( "from table" )
149
+ . ToSqlString ( ) ;
149
150
150
151
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType } ) ;
151
152
}
152
153
153
154
private DbCommand BuildSelectAddCommand ( SqlType paramType )
154
155
{
155
156
var sqlString = new SqlStringBuilder ( )
156
- . Add ( "select col + " )
157
- . AddParameter ( )
158
- . Add ( " from table" )
159
- . ToSqlString ( ) ;
157
+ . Add ( "select col + " )
158
+ . AddParameter ( )
159
+ . Add ( " from table" )
160
+ . ToSqlString ( ) ;
160
161
161
162
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType } ) ;
162
163
}
@@ -172,6 +173,7 @@ private DbCommand BuildInsertWithParamsInSelectCommand(SqlType paramType)
172
173
173
174
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType } ) ;
174
175
}
176
+
175
177
private DbCommand BuildInsertWithParamsInSelectCommandWithSelectInColumnName ( SqlType paramType )
176
178
{
177
179
var sqlString = new SqlStringBuilder ( )
@@ -184,7 +186,7 @@ private DbCommand BuildInsertWithParamsInSelectCommandWithSelectInColumnName(Sql
184
186
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType } ) ;
185
187
}
186
188
187
- private DbCommand BuildInsertWithParamsInSelectCommandWithWhereInColumnName ( SqlType paramType )
189
+ private DbCommand BuildInsertWithParamsInSelectCommandWithWhereInColumnName ( SqlType paramType )
188
190
{
189
191
var sqlString = new SqlStringBuilder ( )
190
192
. Add ( "insert into table1 (col1_where_aaa) " )
0 commit comments