1
- using NHibernate . Driver ;
1
+ using System . Data ;
2
+ using NHibernate . Driver ;
2
3
using NUnit . Framework ;
3
4
using SharpTestsEx ;
4
5
@@ -18,38 +19,48 @@ public class FirebirdClientDriverFixture
18
19
public void ConnectionPooling_OpenThenCloseThenOpenAnotherOne_OnlyOneConnectionIsPooled ( )
19
20
{
20
21
MakeDriver ( ) ;
21
- var connection1 = _driver . CreateConnection ( ) ;
22
- var connection2 = _driver . CreateConnection ( ) ;
23
- connection1 . ConnectionString = _connectionString ;
24
- connection2 . ConnectionString = _connectionString ;
22
+ var connection1 = MakeConnection ( ) ;
23
+ var connection2 = MakeConnection ( ) ;
25
24
25
+ //open first connection
26
26
connection1 . Open ( ) ;
27
- //return the connection1 to the pool
27
+ VerifyCountOfEstablishedConnectionsIs ( 1 ) ;
28
+
29
+ //return it to the pool
28
30
connection1 . Close ( ) ;
31
+ VerifyCountOfEstablishedConnectionsIs ( 1 ) ;
32
+
29
33
//open the second connection
30
34
connection2 . Open ( ) ;
35
+ VerifyCountOfEstablishedConnectionsIs ( 1 ) ;
31
36
32
- var physicalConnections = GetEstablishedConnections ( ) ;
33
- physicalConnections . Should ( ) . Be ( 1 ) ;
37
+ //return it to the pool
38
+ connection2 . Close ( ) ;
39
+ VerifyCountOfEstablishedConnectionsIs ( 1 ) ;
34
40
}
35
41
36
42
[ Test ]
37
43
public void ConnectionPooling_OpenThenCloseTwoAtTheSameTime_TowConnectionsArePooled ( )
38
44
{
39
45
MakeDriver ( ) ;
40
- var connection1 = _driver . CreateConnection ( ) ;
41
- var connection2 = _driver . CreateConnection ( ) ;
42
- connection1 . ConnectionString = _connectionString ;
43
- connection2 . ConnectionString = _connectionString ;
46
+ var connection1 = MakeConnection ( ) ;
47
+ var connection2 = MakeConnection ( ) ;
44
48
49
+ //open first connection
45
50
connection1 . Open ( ) ;
51
+ VerifyCountOfEstablishedConnectionsIs ( 1 ) ;
52
+
53
+ //open second one
46
54
connection2 . Open ( ) ;
47
- //return both to the pool
55
+ VerifyCountOfEstablishedConnectionsIs ( 2 ) ;
56
+
57
+ //return connection1 to the pool
48
58
connection1 . Close ( ) ;
49
- connection2 . Close ( ) ;
59
+ VerifyCountOfEstablishedConnectionsIs ( 2 ) ;
50
60
51
- var physicalConnections = GetEstablishedConnections ( ) ;
52
- physicalConnections . Should ( ) . Be ( 2 ) ;
61
+ //return connection2 to the pool
62
+ connection2 . Close ( ) ;
63
+ VerifyCountOfEstablishedConnectionsIs ( 2 ) ;
53
64
}
54
65
55
66
#endregion
@@ -66,6 +77,19 @@ private void MakeDriver()
66
77
_connectionString = cfg . GetProperty ( "connection.connection_string" ) ;
67
78
}
68
79
80
+ private IDbConnection MakeConnection ( )
81
+ {
82
+ var result = _driver . CreateConnection ( ) ;
83
+ result . ConnectionString = _connectionString ;
84
+ return result ;
85
+ }
86
+
87
+ private void VerifyCountOfEstablishedConnectionsIs ( int expectedCount )
88
+ {
89
+ var physicalConnections = GetEstablishedConnections ( ) ;
90
+ physicalConnections . Should ( ) . Be ( expectedCount ) ;
91
+ }
92
+
69
93
private int GetEstablishedConnections ( )
70
94
{
71
95
using ( var conn = _driver . CreateConnection ( ) )
0 commit comments