6
6
using System . Runtime . Serialization . Formatters . Binary ;
7
7
using NHibernate . Cfg ;
8
8
using NHibernate . Cfg . MappingSchema ;
9
+ using NHibernate . Connection ;
9
10
using NHibernate . Dialect ;
10
11
using NHibernate . Driver ;
11
12
using NHibernate . Engine ;
@@ -24,23 +25,20 @@ public class DatabaseStrategyNoDbSpecificFixture : TestCaseMappingByCode
24
25
25
26
protected override void Configure ( Configuration configuration )
26
27
{
27
- configuration . Properties [ Cfg . Environment . MultiTenancy ] = MultiTenancyStrategy . Database . ToString ( ) ;
28
+ configuration . DataBaseIntegration (
29
+ x =>
30
+ {
31
+ x . MultiTenancy = MultiTenancyStrategy . Database ;
32
+ x . MultiTenancyConnectionProvider < TestMultiTenancyConnectionProvider > ( ) ;
33
+ } ) ;
28
34
configuration . Properties [ Cfg . Environment . GenerateStatistics ] = "true" ;
29
35
base . Configure ( configuration ) ;
30
36
}
31
37
32
38
[ Test ]
33
39
public void ShouldThrowWithNoTenantIdentifier ( )
34
40
{
35
- var sessionBuilder = Sfi . WithOptions ( ) . TenantConfiguration ( new TenantConfiguration ( new MockConnectionProvider ( null , null ) ) ) ;
36
-
37
- Assert . That ( ( ) => sessionBuilder . OpenSession ( ) , Throws . ArgumentException ) ;
38
- }
39
-
40
- [ Test ]
41
- public void ShouldThrowWithNoConnectionAccess ( )
42
- {
43
- var sessionBuilder = Sfi . WithOptions ( ) . TenantConfiguration ( new TenantConfiguration ( new MockConnectionProvider ( "tenant1" , null ) ) ) ;
41
+ var sessionBuilder = Sfi . WithOptions ( ) . TenantConfiguration ( new TenantConfiguration ( null ) ) ;
44
42
45
43
Assert . That ( ( ) => sessionBuilder . OpenSession ( ) , Throws . ArgumentException ) ;
46
44
}
@@ -65,19 +63,11 @@ public void DifferentConnectionStringForDifferentTenants()
65
63
[ Test ]
66
64
public void StatelessSessionShouldThrowWithNoTenantIdentifier ( )
67
65
{
68
- var sessionBuilder = Sfi . WithStatelessOptions ( ) . TenantConfiguration ( new TenantConfiguration ( new MockConnectionProvider ( null , null ) ) ) ;
66
+ var sessionBuilder = Sfi . WithStatelessOptions ( ) . TenantConfiguration ( new TenantConfiguration ( null ) ) ;
69
67
70
68
Assert . That ( ( ) => sessionBuilder . OpenStatelessSession ( ) , Throws . ArgumentException ) ;
71
69
}
72
70
73
- [ Test ]
74
- public void StatelessSessionShouldThrowWithNoConnectionAccess ( )
75
- {
76
- var sessionBuilder = Sfi . WithStatelessOptions ( ) . TenantConfiguration ( new TenantConfiguration ( new MockConnectionProvider ( "tenant1" , null ) ) ) ;
77
-
78
- Assert . That ( ( ) => sessionBuilder . OpenStatelessSession ( ) , Throws . ArgumentException ) ;
79
- }
80
-
81
71
[ Test ]
82
72
public void StatelessSessionDifferentConnectionStringForDifferentTenants ( )
83
73
{
@@ -282,7 +272,10 @@ private IStatelessSession OpenTenantStatelessSession(string tenantId)
282
272
283
273
private TenantConfiguration GetTenantConfig ( string tenantId )
284
274
{
285
- return new TenantConfiguration ( new TestTenantConnectionProvider ( Sfi , tenantId , IsSqlServerDialect ) ) ;
275
+ return new TestTenantConfiguration ( tenantId , IsSqlServerDialect )
276
+ {
277
+ ConnectionString = Sfi . ConnectionProvider . GetConnectionString ( )
278
+ } ;
286
279
}
287
280
288
281
private bool IsSqlServerDialect => Sfi . Dialect is MsSql2000Dialect && ! ( Sfi . ConnectionProvider . Driver is OdbcDriver ) ;
@@ -306,7 +299,8 @@ protected override HbmMapping GetMappings()
306
299
307
300
protected override DbConnection OpenConnectionForSchemaExport ( )
308
301
{
309
- return GetTenantConfig ( "defaultTenant" ) . ConnectionAccess . GetConnection ( ) ;
302
+ return Sfi . Settings . MultiTenancyConnectionProvider
303
+ . GetConnectionAccess ( GetTenantConfig ( "defaultTenant" ) ) . GetConnection ( Sfi . ConnectionProvider ) ;
310
304
}
311
305
312
306
protected override ISession OpenSession ( )
0 commit comments