forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomCurrentSessionTest.cs
55 lines (48 loc) · 1.25 KB
/
CustomCurrentSessionTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using NHibernate.Cfg;
using NHibernate.Context;
using NHibernate.Engine;
using NUnit.Framework;
namespace NHibernate.Test.ConnectionTest
{
[TestFixture]
public class CustomCurrentSessionTest : ConnectionManagementTestCase
{
protected override ISession GetSessionUnderTest()
{
var session = OpenSession();
CustomContext.Session = session;
return session;
}
protected override void Configure(Configuration configuration)
{
base.Configure(cfg);
cfg.SetProperty(Environment.CurrentSessionContextClass, typeof(CustomContext).AssemblyQualifiedName);
}
protected override void Release(ISession session)
{
CustomContext.Session = null;
base.Release(session);
}
[Test]
public void ContextIsSetup()
{
Assert.That(Sfi.CurrentSessionContext, Is.InstanceOf<CustomContext>());
Assert.That(
((CustomContext) Sfi.CurrentSessionContext).Factory,
Is.SameAs(((DebugSessionFactory) Sfi).ActualFactory));
}
}
public class CustomContext : ISessionFactoryAwareCurrentSessionContext
{
internal ISessionFactoryImplementor Factory;
internal static ISession Session;
public ISession CurrentSession()
{
return Session;
}
public void SetFactory(ISessionFactoryImplementor factory)
{
Factory = factory;
}
}
}