2
2
using System . Data ;
3
3
using System . Data . Odbc ;
4
4
using System . Data . SqlClient ;
5
+ using System . Configuration ;
5
6
using System . Transactions ;
6
7
using NHibernate . Dialect ;
7
8
using NHibernate . Driver ;
8
9
using NHibernate . Engine ;
9
10
using NUnit . Framework ;
10
11
12
+ using Environment = NHibernate . Cfg . Environment ;
13
+
11
14
namespace NHibernate . Test . NHSpecificTest . NH2420
12
15
{
13
16
[ TestFixture ]
@@ -23,12 +26,35 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
23
26
return ( dialect is MsSql2005Dialect ) ;
24
27
}
25
28
29
+ private string FetchConnectionStringFromConfiguration ( )
30
+ {
31
+ string connectionString ;
32
+ if ( cfg . Properties . TryGetValue ( Environment . ConnectionString , out connectionString ) )
33
+ {
34
+ Assert . IsNotNullOrEmpty ( connectionString ) ;
35
+ return connectionString ;
36
+ }
37
+ string connectionStringName ;
38
+ if ( cfg . Properties . TryGetValue ( Environment . ConnectionStringName , out connectionStringName ) )
39
+ {
40
+ var connectionStringSettings = ConfigurationManager . ConnectionStrings [ connectionStringName ] ;
41
+ Assert . IsNotNull ( connectionStringSettings ) ;
42
+ connectionString = connectionStringSettings . ConnectionString ;
43
+ Assert . IsNotNullOrEmpty ( connectionString ) ;
44
+ return connectionString ;
45
+ }
46
+ else
47
+ {
48
+ Assert . Fail ( "Unable to find a connection string or connection string name" ) ;
49
+ return string . Empty ;
50
+ }
51
+ }
52
+
26
53
[ Test ]
27
54
public void ShouldBeAbleToReleaseSuppliedConnectionAfterDistributedTransaction ( )
28
55
{
29
- string connectionString = cfg . GetProperty ( "connection.connection_string" ) ;
56
+ string connectionString = FetchConnectionStringFromConfiguration ( ) ;
30
57
ISession s ;
31
-
32
58
using ( var ts = new TransactionScope ( ) )
33
59
{
34
60
// Enlisting DummyEnlistment as a durable resource manager will start
0 commit comments