Skip to content

Commit 7acee28

Browse files
committed
Update test
1 parent 2662dc3 commit 7acee28

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

src/NHibernate.Test/Async/Linq/ConstantTest.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,28 @@ public async Task DmlPlansAreCachedAsync()
248248
.GetValue(Sfi.QueryPlanCache);
249249
cache.Clear();
250250

251-
await (db.Customers.Where(c => c.CustomerId == "ALFKI").UpdateAsync(x => new Customer {CompanyName = x.CompanyName}));
252-
Assert.That(
253-
cache,
254-
Has.Count.EqualTo(1),
255-
"First query plan should be cached.");
256-
257-
using (var spy = new LogSpy(queryPlanCacheType))
251+
using (session.BeginTransaction())
258252
{
259-
// Should hit plan cache.
260253
await (db.Customers.Where(c => c.CustomerId == "ALFKI").UpdateAsync(x => new Customer {CompanyName = x.CompanyName}));
261-
Assert.That(cache, Has.Count.EqualTo(1), "Second query should not cause a plan to be cache.");
262254
Assert.That(
263-
spy.GetWholeLog(),
264-
Does
265-
.Contain("located HQL query plan in cache")
266-
.And.Not.Contain("unable to locate HQL query plan in cache"));
255+
cache,
256+
Has.Count.EqualTo(1),
257+
"First query plan should be cached.");
258+
259+
using (var spy = new LogSpy(queryPlanCacheType))
260+
{
261+
// Should hit plan cache.
262+
await (db.Customers.Where(c => c.CustomerId == "ANATR").UpdateAsync(x => new Customer {CompanyName = x.CompanyName}));
263+
Assert.That(cache, Has.Count.EqualTo(1), "Second query should not cause a plan to be cached.");
264+
Assert.That(
265+
spy.GetWholeLog(),
266+
Does
267+
.Contain("located HQL query plan in cache")
268+
.And.Not.Contain("unable to locate HQL query plan in cache"));
269+
270+
await (db.Customers.Where(c => c.CustomerId == "ANATR").UpdateAsync(x => new Customer {ContactName = x.ContactName}));
271+
Assert.That(cache, Has.Count.EqualTo(2), "Third query should be cached");
272+
}
267273
}
268274
}
269275

src/NHibernate.Test/Linq/ConstantTest.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,28 @@ public void DmlPlansAreCached()
269269
.GetValue(Sfi.QueryPlanCache);
270270
cache.Clear();
271271

272-
db.Customers.Where(c => c.CustomerId == "ALFKI").Update(x => new Customer {CompanyName = x.CompanyName});
273-
Assert.That(
274-
cache,
275-
Has.Count.EqualTo(1),
276-
"First query plan should be cached.");
277-
278-
using (var spy = new LogSpy(queryPlanCacheType))
272+
using (session.BeginTransaction())
279273
{
280-
// Should hit plan cache.
281274
db.Customers.Where(c => c.CustomerId == "ALFKI").Update(x => new Customer {CompanyName = x.CompanyName});
282-
Assert.That(cache, Has.Count.EqualTo(1), "Second query should not cause a plan to be cache.");
283275
Assert.That(
284-
spy.GetWholeLog(),
285-
Does
286-
.Contain("located HQL query plan in cache")
287-
.And.Not.Contain("unable to locate HQL query plan in cache"));
276+
cache,
277+
Has.Count.EqualTo(1),
278+
"First query plan should be cached.");
279+
280+
using (var spy = new LogSpy(queryPlanCacheType))
281+
{
282+
// Should hit plan cache.
283+
db.Customers.Where(c => c.CustomerId == "ANATR").Update(x => new Customer {CompanyName = x.CompanyName});
284+
Assert.That(cache, Has.Count.EqualTo(1), "Second query should not cause a plan to be cached.");
285+
Assert.That(
286+
spy.GetWholeLog(),
287+
Does
288+
.Contain("located HQL query plan in cache")
289+
.And.Not.Contain("unable to locate HQL query plan in cache"));
290+
291+
db.Customers.Where(c => c.CustomerId == "ANATR").Update(x => new Customer {ContactName = x.ContactName});
292+
Assert.That(cache, Has.Count.EqualTo(2), "Third query should be cached");
293+
}
288294
}
289295
}
290296

0 commit comments

Comments
 (0)