Skip to content

Commit 3f76ffa

Browse files
Prevent substitute garbage collection
1 parent 45a63bf commit 3f76ffa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/NHibernate.Test/Linq/ByMethod/WithOptionsTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public void AppliesOptionsToQuery()
4141
query.Received(1).SetCacheMode(CacheMode.Normal);
4242
query.Received(1).SetCacheRegion("testregion");
4343
query.Received(1).SetTimeout(10);
44+
45+
// Prevent garbage collection of session substitute before end of test, since the Linq query provider
46+
// only has a weak reference on it.
47+
Assert.That(session, Is.Not.Null);
4448
}
4549

4650
[Test]
@@ -72,6 +76,10 @@ public void DoNotContaminateQueryWithOptions()
7276
query.Received(1).SetCacheMode(CacheMode.Normal);
7377
query.Received(1).SetCacheRegion("testregion");
7478
query.Received(1).SetTimeout(10);
79+
80+
// Prevent garbage collection of session substitute before end of test, since the Linq query provider
81+
// only has a weak reference on it.
82+
Assert.That(session, Is.Not.Null);
7583
}
7684

7785
[Test]
@@ -101,6 +109,10 @@ public async Task AppliesOptionsToQueryAsync()
101109
query.Received(1).SetCacheMode(CacheMode.Normal);
102110
query.Received(1).SetCacheRegion("testregion");
103111
query.Received(1).SetTimeout(10);
112+
113+
// Prevent garbage collection of session substitute before end of test, since the Linq query provider
114+
// only has a weak reference on it.
115+
Assert.That(session, Is.Not.Null);
104116
}
105117

106118
[Test]
@@ -133,6 +145,10 @@ public async Task DoNotContaminateQueryWithOptionsAsync()
133145
query.Received(1).SetCacheMode(CacheMode.Normal);
134146
query.Received(1).SetCacheRegion("testregion");
135147
query.Received(1).SetTimeout(10);
148+
149+
// Prevent garbage collection of session substitute before end of test, since the Linq query provider
150+
// only has a weak reference on it.
151+
Assert.That(session, Is.Not.Null);
136152
}
137153
}
138154
}

0 commit comments

Comments
 (0)