@@ -14,157 +14,160 @@ public class FirebirdClientDriverFixture
14
14
private string _connectionString ;
15
15
private FirebirdClientDriver _driver ;
16
16
17
+ [ OneTimeSetUp ]
18
+ public void OneTimeSetup ( )
19
+ {
20
+ var cfg = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
21
+
22
+ var dlct = cfg . GetProperty ( "dialect" ) ;
23
+ if ( ! dlct . Contains ( "Firebird" ) )
24
+ Assert . Ignore ( "Applies only to Firebird" ) ;
25
+
26
+ _driver = new FirebirdClientDriver ( ) ;
27
+ _driver . Configure ( cfg . Properties ) ;
28
+ _connectionString = cfg . GetProperty ( "connection.connection_string" ) ;
29
+ }
30
+
17
31
[ Test ]
18
32
public void ConnectionPooling_OpenThenCloseThenOpenAnotherOne_OnlyOneConnectionIsPooled ( )
19
33
{
20
- MakeDriver ( ) ;
21
-
22
34
_driver . ClearPool ( _connectionString ) ;
23
35
24
36
var allreadyEstablished = GetEstablishedConnections ( ) ;
25
37
26
- var connection1 = MakeConnection ( ) ;
27
- var connection2 = MakeConnection ( ) ;
28
-
29
- //open first connection
30
- connection1 . Open ( ) ;
31
- VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After first open" ) ;
38
+ using ( var connection1 = MakeConnection ( ) )
39
+ using ( var connection2 = MakeConnection ( ) )
40
+ {
41
+ //open first connection
42
+ connection1 . Open ( ) ;
43
+ VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After first open" ) ;
32
44
33
- //return it to the pool
34
- connection1 . Close ( ) ;
35
- VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After first close" ) ;
45
+ //return it to the pool
46
+ connection1 . Close ( ) ;
47
+ VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After first close" ) ;
36
48
37
- //open the second connection
38
- connection2 . Open ( ) ;
39
- VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After second open" ) ;
49
+ //open the second connection
50
+ connection2 . Open ( ) ;
51
+ VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After second open" ) ;
40
52
41
- //return it to the pool
42
- connection2 . Close ( ) ;
43
- VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After second close" ) ;
53
+ //return it to the pool
54
+ connection2 . Close ( ) ;
55
+ VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After second close" ) ;
56
+ }
44
57
}
45
58
46
59
[ Test ]
47
60
public void ConnectionPooling_OpenThenCloseTwoAtTheSameTime_TowConnectionsArePooled ( )
48
61
{
49
- MakeDriver ( ) ;
50
-
51
62
_driver . ClearPool ( _connectionString ) ;
52
63
53
64
var allreadyEstablished = GetEstablishedConnections ( ) ;
54
65
55
- var connection1 = MakeConnection ( ) ;
56
- var connection2 = MakeConnection ( ) ;
57
-
58
- //open first connection
59
- connection1 . Open ( ) ;
60
- VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After first open" ) ;
66
+ using ( var connection1 = MakeConnection ( ) )
67
+ using ( var connection2 = MakeConnection ( ) )
68
+ {
69
+ //open first connection
70
+ connection1 . Open ( ) ;
71
+ VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 1 , "After first open" ) ;
61
72
62
- //open second one
63
- connection2 . Open ( ) ;
64
- VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 2 , "After second open" ) ;
73
+ //open second one
74
+ connection2 . Open ( ) ;
75
+ VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 2 , "After second open" ) ;
65
76
66
- //return connection1 to the pool
67
- connection1 . Close ( ) ;
68
- VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 2 , "After first close" ) ;
77
+ //return connection1 to the pool
78
+ connection1 . Close ( ) ;
79
+ VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 2 , "After first close" ) ;
69
80
70
- //return connection2 to the pool
71
- connection2 . Close ( ) ;
72
- VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 2 , "After second close" ) ;
81
+ //return connection2 to the pool
82
+ connection2 . Close ( ) ;
83
+ VerifyCountOfEstablishedConnectionsIs ( allreadyEstablished + 2 , "After second close" ) ;
84
+ }
73
85
}
74
86
75
87
[ Test ]
76
88
public void AdjustCommand_StringParametersWithinConditionalSelect_ThenParameterIsWrappedByAVarcharCastStatement ( )
77
89
{
78
- MakeDriver ( ) ;
79
- var cmd = BuildSelectCaseCommand ( SqlTypeFactory . GetString ( 255 ) ) ;
80
-
81
- _driver . AdjustCommand ( cmd ) ;
90
+ using ( var cmd = BuildSelectCaseCommand ( SqlTypeFactory . GetString ( 255 ) ) )
91
+ {
92
+ _driver . AdjustCommand ( cmd ) ;
82
93
83
- var expectedCommandTxt = "select (case when col = @p0 then cast(@p1 as VARCHAR(255)) else cast(@p2 as VARCHAR(255)) end) from table" ;
84
- Assert . That ( cmd . CommandText , Is . EqualTo ( expectedCommandTxt ) ) ;
94
+ var expectedCommandTxt =
95
+ "select (case when col = @p0 then cast(@p1 as VARCHAR(4000)) else cast(@p2 as VARCHAR(4000)) end) from table" ;
96
+ Assert . That ( cmd . CommandText , Is . EqualTo ( expectedCommandTxt ) ) ;
97
+ }
85
98
}
86
99
87
100
[ Test ]
88
101
public void AdjustCommand_IntParametersWithinConditionalSelect_ThenParameterIsWrappedByAnIntCastStatement ( )
89
102
{
90
- MakeDriver ( ) ;
91
- var cmd = BuildSelectCaseCommand ( SqlTypeFactory . Int32 ) ;
92
-
93
- _driver . AdjustCommand ( cmd ) ;
103
+ using ( var cmd = BuildSelectCaseCommand ( SqlTypeFactory . Int32 ) )
104
+ {
105
+ _driver . AdjustCommand ( cmd ) ;
94
106
95
- var expectedCommandTxt = "select (case when col = @p0 then cast(@p1 as INTEGER) else cast(@p2 as INTEGER) end) from table" ;
96
- Assert . That ( cmd . CommandText , Is . EqualTo ( expectedCommandTxt ) ) ;
107
+ var expectedCommandTxt =
108
+ "select (case when col = @p0 then cast(@p1 as INTEGER) else cast(@p2 as INTEGER) end) from table" ;
109
+ Assert . That ( cmd . CommandText , Is . EqualTo ( expectedCommandTxt ) ) ;
110
+ }
97
111
}
98
112
99
113
[ Test ]
100
114
public void AdjustCommand_ParameterWithinSelectConcat_ParameterIsCasted ( )
101
115
{
102
- MakeDriver ( ) ;
103
- var cmd = BuildSelectConcatCommand ( SqlTypeFactory . GetString ( 255 ) ) ;
104
-
105
- _driver . AdjustCommand ( cmd ) ;
116
+ using ( var cmd = BuildSelectConcatCommand ( SqlTypeFactory . GetString ( 255 ) ) )
117
+ {
118
+ _driver . AdjustCommand ( cmd ) ;
106
119
107
- var expected = "select col || cast(@p0 as VARCHAR(255)) || col from table" ;
108
- Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
120
+ var expected = "select col || cast(@p0 as VARCHAR(4000)) || col from table" ;
121
+ Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
122
+ }
109
123
}
110
124
111
125
[ Test ]
112
126
public void AdjustCommand_ParameterWithinSelectAddFunction_ParameterIsCasted ( )
113
127
{
114
- MakeDriver ( ) ;
115
- var cmd = BuildSelectAddCommand ( SqlTypeFactory . GetString ( 255 ) ) ;
116
-
117
- _driver . AdjustCommand ( cmd ) ;
128
+ using ( var cmd = BuildSelectAddCommand ( SqlTypeFactory . GetString ( 255 ) ) )
129
+ {
130
+ _driver . AdjustCommand ( cmd ) ;
118
131
119
- var expected = "select col + cast(@p0 as VARCHAR(255)) from table" ;
120
- Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
132
+ var expected = "select col + cast(@p0 as VARCHAR(4000)) from table" ;
133
+ Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
134
+ }
121
135
}
122
136
123
137
[ Test ]
124
138
public void AdjustCommand_InsertWithParamsInSelect_ParameterIsCasted ( )
125
139
{
126
- MakeDriver ( ) ;
127
- var cmd = BuildInsertWithParamsInSelectCommand ( SqlTypeFactory . Int32 ) ;
128
-
129
- _driver . AdjustCommand ( cmd ) ;
140
+ using ( var cmd = BuildInsertWithParamsInSelectCommand ( SqlTypeFactory . Int32 ) )
141
+ {
142
+ _driver . AdjustCommand ( cmd ) ;
130
143
131
- var expected = "insert into table1 (col1, col2) select col1, cast(@p0 as INTEGER) from table2" ;
132
- Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
144
+ var expected = "insert into table1 (col1, col2) select col1, cast(@p0 as INTEGER) from table2" ;
145
+ Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
146
+ }
133
147
}
134
148
135
149
[ Test ]
136
150
public void AdjustCommand_InsertWithParamsInSelect_ParameterIsNotCasted_WhenColumnNameContainsSelect ( )
137
151
{
138
- MakeDriver ( ) ;
139
- var cmd = BuildInsertWithParamsInSelectCommandWithSelectInColumnName ( SqlTypeFactory . Int32 ) ;
140
-
141
- _driver . AdjustCommand ( cmd ) ;
152
+ using ( var cmd = BuildInsertWithParamsInSelectCommandWithSelectInColumnName ( SqlTypeFactory . Int32 ) )
153
+ {
154
+ _driver . AdjustCommand ( cmd ) ;
142
155
143
- var expected = "insert into table1 (col1_select_aaa) values(@p0) from table2" ;
144
- Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
156
+ var expected = "insert into table1 (col1_select_aaa) values(@p0) from table2" ;
157
+ Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
158
+ }
145
159
}
146
160
147
161
[ Test ]
148
162
public void AdjustCommand_InsertWithParamsInSelect_ParameterIsNotCasted_WhenColumnNameContainsWhere ( )
149
163
{
150
- MakeDriver ( ) ;
151
- var cmd = BuildInsertWithParamsInSelectCommandWithWhereInColumnName ( SqlTypeFactory . Int32 ) ;
152
-
153
- _driver . AdjustCommand ( cmd ) ;
154
-
155
- var expected = "insert into table1 (col1_where_aaa) values(@p0) from table2" ;
156
- Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
157
- }
158
-
159
- private void MakeDriver ( )
160
- {
161
- var cfg = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
162
- var dlct = cfg . GetProperty ( "dialect" ) ;
163
- if ( ! dlct . Contains ( "Firebird" ) )
164
- Assert . Ignore ( "Applies only to Firebird" ) ;
164
+ using ( var cmd = BuildInsertWithParamsInSelectCommandWithWhereInColumnName ( SqlTypeFactory . Int32 ) )
165
+ {
166
+ _driver . AdjustCommand ( cmd ) ;
165
167
166
- _driver = new FirebirdClientDriver ( ) ;
167
- _connectionString = cfg . GetProperty ( "connection.connection_string" ) ;
168
+ var expected = "insert into table1 (col1_where_aaa) values(@p0) from table2" ;
169
+ Assert . That ( cmd . CommandText , Is . EqualTo ( expected ) ) ;
170
+ }
168
171
}
169
172
170
173
private DbConnection MakeConnection ( )
@@ -197,38 +200,38 @@ private int GetEstablishedConnections()
197
200
private DbCommand BuildSelectCaseCommand ( SqlType paramType )
198
201
{
199
202
var sqlString = new SqlStringBuilder ( )
200
- . Add ( "select (case when col = " )
201
- . AddParameter ( )
202
- . Add ( " then " )
203
- . AddParameter ( )
204
- . Add ( " else " )
205
- . AddParameter ( )
206
- . Add ( " end) from table" )
207
- . ToSqlString ( ) ;
203
+ . Add ( "select (case when col = " )
204
+ . AddParameter ( )
205
+ . Add ( " then " )
206
+ . AddParameter ( )
207
+ . Add ( " else " )
208
+ . AddParameter ( )
209
+ . Add ( " end) from table" )
210
+ . ToSqlString ( ) ;
208
211
209
212
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType , paramType , paramType } ) ;
210
213
}
211
214
212
215
private DbCommand BuildSelectConcatCommand ( SqlType paramType )
213
216
{
214
217
var sqlString = new SqlStringBuilder ( )
215
- . Add ( "select col || " )
216
- . AddParameter ( )
217
- . Add ( " || " )
218
- . Add ( "col " )
219
- . Add ( "from table" )
220
- . ToSqlString ( ) ;
218
+ . Add ( "select col || " )
219
+ . AddParameter ( )
220
+ . Add ( " || " )
221
+ . Add ( "col " )
222
+ . Add ( "from table" )
223
+ . ToSqlString ( ) ;
221
224
222
225
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType } ) ;
223
226
}
224
227
225
228
private DbCommand BuildSelectAddCommand ( SqlType paramType )
226
229
{
227
230
var sqlString = new SqlStringBuilder ( )
228
- . Add ( "select col + " )
229
- . AddParameter ( )
230
- . Add ( " from table" )
231
- . ToSqlString ( ) ;
231
+ . Add ( "select col + " )
232
+ . AddParameter ( )
233
+ . Add ( " from table" )
234
+ . ToSqlString ( ) ;
232
235
233
236
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType } ) ;
234
237
}
@@ -244,6 +247,7 @@ private DbCommand BuildInsertWithParamsInSelectCommand(SqlType paramType)
244
247
245
248
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType } ) ;
246
249
}
250
+
247
251
private DbCommand BuildInsertWithParamsInSelectCommandWithSelectInColumnName ( SqlType paramType )
248
252
{
249
253
var sqlString = new SqlStringBuilder ( )
@@ -256,7 +260,7 @@ private DbCommand BuildInsertWithParamsInSelectCommandWithSelectInColumnName(Sql
256
260
return _driver . GenerateCommand ( CommandType . Text , sqlString , new [ ] { paramType } ) ;
257
261
}
258
262
259
- private DbCommand BuildInsertWithParamsInSelectCommandWithWhereInColumnName ( SqlType paramType )
263
+ private DbCommand BuildInsertWithParamsInSelectCommandWithWhereInColumnName ( SqlType paramType )
260
264
{
261
265
var sqlString = new SqlStringBuilder ( )
262
266
. Add ( "insert into table1 (col1_where_aaa) " )
0 commit comments