forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatelessSessionQueryFixture.cs
123 lines (104 loc) · 2.56 KB
/
StatelessSessionQueryFixture.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System.Collections;
using NHibernate.Cfg;
using NUnit.Framework;
namespace NHibernate.Test.Stateless
{
[TestFixture]
public class StatelessSessionQueryFixture : TestCase
{
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}
protected override string[] Mappings
{
get { return new[] {"Stateless.Contact.hbm.xml"}; }
}
protected override void Configure(Configuration configuration)
{
base.Configure(configuration);
cfg.SetProperty(Environment.MaxFetchDepth, 1.ToString());
}
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInsertsOrHasNonIdentityNativeGenerator;
}
private class TestData
{
internal readonly IList list = new ArrayList();
private readonly ISessionFactory sessions;
public TestData(ISessionFactory sessions)
{
this.sessions = sessions;
}
public virtual void createData()
{
using (ISession session = sessions.OpenSession())
{
using (ITransaction tx = session.BeginTransaction())
{
var usa = new Country();
session.Save(usa);
list.Add(usa);
var disney = new Org();
disney.Country = usa;
session.Save(disney);
list.Add(disney);
var waltDisney = new Contact();
waltDisney.Org = disney;
session.Save(waltDisney);
list.Add(waltDisney);
tx.Commit();
}
}
}
public virtual void cleanData()
{
using (ISession session = sessions.OpenSession())
{
using (ITransaction tx = session.BeginTransaction())
{
foreach (object obj in list)
{
session.Delete(obj);
}
tx.Commit();
}
}
}
}
[Test]
public void Criteria()
{
var testData = new TestData(Sfi);
testData.createData();
using (IStatelessSession s = Sfi.OpenStatelessSession())
{
Assert.AreEqual(1, s.CreateCriteria<Contact>().List().Count);
}
testData.cleanData();
}
[Test]
public void CriteriaWithSelectFetchMode()
{
var testData = new TestData(Sfi);
testData.createData();
using (IStatelessSession s = Sfi.OpenStatelessSession())
{
Assert.AreEqual(1, s.CreateCriteria<Contact>().Fetch(SelectMode.Skip, "Org").List().Count);
}
testData.cleanData();
}
[Test]
public void Hql()
{
var testData = new TestData(Sfi);
testData.createData();
using (IStatelessSession s = Sfi.OpenStatelessSession())
{
Assert.AreEqual(1, s.CreateQuery("from Contact c join fetch c.Org join fetch c.Org.Country").List<Contact>().Count);
}
testData.cleanData();
}
}
}