Skip to content

Commit f8bd460

Browse files
committed
refactored the tests to make its intention more clear
1 parent b39ded0 commit f8bd460

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

src/NHibernate.Test/DriverTest/FirebirdClientDriverFixture.cs

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NHibernate.Driver;
1+
using System.Data;
2+
using NHibernate.Driver;
23
using NUnit.Framework;
34
using SharpTestsEx;
45

@@ -18,38 +19,48 @@ public class FirebirdClientDriverFixture
1819
public void ConnectionPooling_OpenThenCloseThenOpenAnotherOne_OnlyOneConnectionIsPooled()
1920
{
2021
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();
2524

25+
//open first connection
2626
connection1.Open();
27-
//return the connection1 to the pool
27+
VerifyCountOfEstablishedConnectionsIs(1);
28+
29+
//return it to the pool
2830
connection1.Close();
31+
VerifyCountOfEstablishedConnectionsIs(1);
32+
2933
//open the second connection
3034
connection2.Open();
35+
VerifyCountOfEstablishedConnectionsIs(1);
3136

32-
var physicalConnections = GetEstablishedConnections();
33-
physicalConnections.Should().Be(1);
37+
//return it to the pool
38+
connection2.Close();
39+
VerifyCountOfEstablishedConnectionsIs(1);
3440
}
3541

3642
[Test]
3743
public void ConnectionPooling_OpenThenCloseTwoAtTheSameTime_TowConnectionsArePooled()
3844
{
3945
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();
4448

49+
//open first connection
4550
connection1.Open();
51+
VerifyCountOfEstablishedConnectionsIs(1);
52+
53+
//open second one
4654
connection2.Open();
47-
//return both to the pool
55+
VerifyCountOfEstablishedConnectionsIs(2);
56+
57+
//return connection1 to the pool
4858
connection1.Close();
49-
connection2.Close();
59+
VerifyCountOfEstablishedConnectionsIs(2);
5060

51-
var physicalConnections = GetEstablishedConnections();
52-
physicalConnections.Should().Be(2);
61+
//return connection2 to the pool
62+
connection2.Close();
63+
VerifyCountOfEstablishedConnectionsIs(2);
5364
}
5465

5566
#endregion
@@ -66,6 +77,19 @@ private void MakeDriver()
6677
_connectionString = cfg.GetProperty("connection.connection_string");
6778
}
6879

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+
6993
private int GetEstablishedConnections()
7094
{
7195
using (var conn = _driver.CreateConnection())

0 commit comments

Comments
 (0)