Skip to content

Commit eb92dba

Browse files
Use transactions
1 parent 56e4ebe commit eb92dba

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/NHibernate.Test/Async/CacheTest/QueryCacheFixture.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,37 @@ public async Task QueryCacheWithScalarReturnAsync()
106106
[Test]
107107
public async Task QueryCacheWithAliasToBeanTransformerAsync()
108108
{
109+
const string query = "select s.id_ as Id from Simple as s;";
110+
109111
using (var s = OpenSession())
112+
using (var t = s.BeginTransaction())
110113
{
111-
const string query = "select s.id_ as Id from Simple as s;";
112114
var result1 = await (s
113115
.CreateSQLQuery(query)
114116
.SetCacheable(true)
115117
.SetResultTransformer(Transformers.AliasToBean<SimpleDTO>())
116118
.UniqueResultAsync());
117119

118120
Assert.That(result1, Is.InstanceOf<SimpleDTO>());
119-
var dto1 = (SimpleDTO)result1;
121+
var dto1 = (SimpleDTO) result1;
120122
Assert.That(dto1.Id, Is.EqualTo(1));
123+
await (t.CommitAsync());
124+
}
121125

122-
// Run a second time, just to test the query cache
126+
// Run a second time, just to test the query cache
127+
using (var s = OpenSession())
128+
using (var t = s.BeginTransaction())
129+
{
123130
var result2 = await (s
124131
.CreateSQLQuery(query)
125132
.SetCacheable(true)
126133
.SetResultTransformer(Transformers.AliasToBean<SimpleDTO>())
127134
.UniqueResultAsync());
128135

129136
Assert.That(result2, Is.InstanceOf<SimpleDTO>());
130-
var dto2 = (SimpleDTO)result2;
137+
var dto2 = (SimpleDTO) result2;
131138
Assert.That(dto2.Id, Is.EqualTo(1));
139+
await (t.CommitAsync());
132140
}
133141
}
134142

src/NHibernate.Test/CacheTest/QueryCacheFixture.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,37 @@ public void QueryCacheWithScalarReturn()
9595
[Test]
9696
public void QueryCacheWithAliasToBeanTransformer()
9797
{
98+
const string query = "select s.id_ as Id from Simple as s;";
99+
98100
using (var s = OpenSession())
101+
using (var t = s.BeginTransaction())
99102
{
100-
const string query = "select s.id_ as Id from Simple as s;";
101103
var result1 = s
102104
.CreateSQLQuery(query)
103105
.SetCacheable(true)
104106
.SetResultTransformer(Transformers.AliasToBean<SimpleDTO>())
105107
.UniqueResult();
106108

107109
Assert.That(result1, Is.InstanceOf<SimpleDTO>());
108-
var dto1 = (SimpleDTO)result1;
110+
var dto1 = (SimpleDTO) result1;
109111
Assert.That(dto1.Id, Is.EqualTo(1));
112+
t.Commit();
113+
}
110114

111-
// Run a second time, just to test the query cache
115+
// Run a second time, just to test the query cache
116+
using (var s = OpenSession())
117+
using (var t = s.BeginTransaction())
118+
{
112119
var result2 = s
113120
.CreateSQLQuery(query)
114121
.SetCacheable(true)
115122
.SetResultTransformer(Transformers.AliasToBean<SimpleDTO>())
116123
.UniqueResult();
117124

118125
Assert.That(result2, Is.InstanceOf<SimpleDTO>());
119-
var dto2 = (SimpleDTO)result2;
126+
var dto2 = (SimpleDTO) result2;
120127
Assert.That(dto2.Id, Is.EqualTo(1));
128+
t.Commit();
121129
}
122130
}
123131

0 commit comments

Comments
 (0)