Skip to content

Commit 9db2e3e

Browse files
committed
Ignore Future tests if not supported
1 parent c9469a7 commit 9db2e3e

File tree

2 files changed

+173
-6
lines changed

2 files changed

+173
-6
lines changed

src/NHibernate.Test/Async/Criteria/SelectModeTest/SelectModeTest.cs

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ public async Task SelectModeFetchLazyPropertiesAsync()
134134

135135

136136
[Test]
137-
public async Task SelectModeChildFetchForMultipleCollectionsAsync()
137+
public async Task SelectModeChildFetchForMultipleCollections_SingleDbRoundtripAsync()
138138
{
139+
SkipFutureTestIfNotSupported();
140+
139141
using (var sqlLog = new SqlLogSpy())
140142
using (var session = OpenSession())
141143
{
@@ -172,6 +174,41 @@ public async Task SelectModeChildFetchForMultipleCollectionsAsync()
172174
}
173175
}
174176

177+
[Test]
178+
public async Task SelectModeChildFetchForMultipleCollectionsAsync()
179+
{
180+
using (var session = OpenSession())
181+
{
182+
EntityComplex root = null;
183+
root = await (session
184+
.QueryOver(() => root)
185+
.Where(r => r.Id == _parentEntityComplexId)
186+
.SingleOrDefaultAsync());
187+
188+
await (session
189+
.QueryOver(() => root)
190+
//Only ID is added to SELECT statement for root so it's index scan only
191+
.With(SelectMode.ChildFetch, ec => ec)
192+
.With(SelectMode.Fetch, ec => ec.ChildrenList)
193+
.Where(r => r.Id == _parentEntityComplexId)
194+
.ListAsync());
195+
196+
await (session
197+
.QueryOver(() => root)
198+
.With(SelectMode.ChildFetch, ec => ec)
199+
.With(SelectMode.Fetch, ec => ec.ChildrenListEmpty)
200+
.Where(r => r.Id == _parentEntityComplexId)
201+
.ListAsync());
202+
203+
Assert.That(root?.ChildrenList, Is.Not.Null);
204+
Assert.That(root?.ChildrenListEmpty, Is.Not.Null);
205+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenList), "ChildrenList must be initialized");
206+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenListEmpty), "ChildrenListEmpty must be initialized");
207+
Assert.That(root?.ChildrenList, Is.Not.Empty, "ChildrenList must not be empty");
208+
Assert.That(root?.ChildrenListEmpty, Is.Empty, "ChildrenListEmpty must be empty");
209+
}
210+
}
211+
175212
[Test]
176213
public async Task SelectModeSkipEntityJoinAsync()
177214
{
@@ -198,7 +235,7 @@ public async Task SelectModeSkipEntityJoinAsync()
198235

199236

200237
[Test]
201-
public async Task SelectModeFetchLazyPropertiesForEntityAliasAsync()
238+
public async Task SelectModeFetchLazyPropertiesForEntityJoinAsync()
202239
{
203240
using (var sqlLog = new SqlLogSpy())
204241
using (var session = OpenSession())
@@ -242,7 +279,45 @@ public async Task SelectModeChildFetchReturnsNullForNotLoadedObjectAndDoesntThro
242279
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
243280
}
244281
}
282+
283+
[Test]
284+
public async Task SelectModeChildFetchDeep_AliasedAsync()
285+
{
286+
using (var session = OpenSession())
287+
{
288+
EntityComplex root = null;
289+
var list = await (session
290+
.QueryOver(() => root)
291+
.ListAsync());
245292

293+
await (session
294+
.QueryOver(() => root)
295+
.With(SelectMode.ChildFetch, () => root)
296+
.With(SelectMode.Fetch, () => root.ChildrenList)
297+
.ListAsync());
298+
299+
await (session
300+
.QueryOver(() => root)
301+
.With(SelectMode.ChildFetch, () => root, () => root.ChildrenList)
302+
.With(SelectMode.Fetch, () => root.ChildrenList[0].Children)
303+
.ListAsync());
304+
305+
await (session
306+
.QueryOver(() => root)
307+
.With(SelectMode.Skip, () => root.ChildrenList)
308+
.With(SelectMode.ChildFetch,() => root, () => root.ChildrenList[0].Children)
309+
.With(SelectMode.Fetch, () => root.ChildrenList[0].Children[0].Children)
310+
.ListAsync());
311+
312+
root = list.First(r => r.Id == _parentEntityComplexId);
313+
314+
315+
Assert.That(root?.ChildrenList, Is.Not.Null);
316+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenList));
317+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenList[0].Children));
318+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenList[0].Children[0].Children));
319+
}
320+
}
246321

247322
[Test]
248323
public void SkipRootEntityIsNotSupportedAsync()
@@ -259,6 +334,13 @@ public void SkipRootEntityIsNotSupportedAsync()
259334
}
260335
}
261336

337+
private void SkipFutureTestIfNotSupported()
338+
{
339+
var driver = Sfi.ConnectionProvider.Driver;
340+
if (driver.SupportsMultipleQueries == false)
341+
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
342+
}
343+
262344
#region Test Setup
263345

264346
protected override HbmMapping GetMappings()

src/NHibernate.Test/Criteria/SelectModeTest/SelectModeTest.cs

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ public void SelectModeFetchLazyProperties()
123123

124124

125125
[Test]
126-
public void SelectModeChildFetchForMultipleCollections()
126+
public void SelectModeChildFetchForMultipleCollections_SingleDbRoundtrip()
127127
{
128+
SkipFutureTestIfNotSupported();
129+
128130
using (var sqlLog = new SqlLogSpy())
129131
using (var session = OpenSession())
130132
{
@@ -161,6 +163,41 @@ public void SelectModeChildFetchForMultipleCollections()
161163
}
162164
}
163165

166+
[Test]
167+
public void SelectModeChildFetchForMultipleCollections()
168+
{
169+
using (var session = OpenSession())
170+
{
171+
EntityComplex root = null;
172+
root = session
173+
.QueryOver(() => root)
174+
.Where(r => r.Id == _parentEntityComplexId)
175+
.SingleOrDefault();
176+
177+
session
178+
.QueryOver(() => root)
179+
//Only ID is added to SELECT statement for root so it's index scan only
180+
.With(SelectMode.ChildFetch, ec => ec)
181+
.With(SelectMode.Fetch, ec => ec.ChildrenList)
182+
.Where(r => r.Id == _parentEntityComplexId)
183+
.List();
184+
185+
session
186+
.QueryOver(() => root)
187+
.With(SelectMode.ChildFetch, ec => ec)
188+
.With(SelectMode.Fetch, ec => ec.ChildrenListEmpty)
189+
.Where(r => r.Id == _parentEntityComplexId)
190+
.List();
191+
192+
Assert.That(root?.ChildrenList, Is.Not.Null);
193+
Assert.That(root?.ChildrenListEmpty, Is.Not.Null);
194+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenList), "ChildrenList must be initialized");
195+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenListEmpty), "ChildrenListEmpty must be initialized");
196+
Assert.That(root?.ChildrenList, Is.Not.Empty, "ChildrenList must not be empty");
197+
Assert.That(root?.ChildrenListEmpty, Is.Empty, "ChildrenListEmpty must be empty");
198+
}
199+
}
200+
164201
[Test]
165202
public void SelectModeSkipEntityJoin()
166203
{
@@ -187,7 +224,7 @@ public void SelectModeSkipEntityJoin()
187224

188225

189226
[Test]
190-
public void SelectModeFetchLazyPropertiesForEntityAlias()
227+
public void SelectModeFetchLazyPropertiesForEntityJoin()
191228
{
192229
using (var sqlLog = new SqlLogSpy())
193230
using (var session = OpenSession())
@@ -235,12 +272,15 @@ public void SelectModeChildFetchReturnsNullForNotLoadedObjectAndDoesntThrowExcep
235272
[Test]
236273
public void SelectModeChildFetchDeep_SingleDbRoundtrip_Aliased()
237274
{
275+
SkipFutureTestIfNotSupported();
276+
238277
using (var sqlLog = new SqlLogSpy())
239278
using (var session = OpenSession())
240279
{
241280
EntityComplex root = null;
242-
var rootFuture = session.QueryOver(() => root)
243-
.Future();
281+
var rootFuture = session
282+
.QueryOver(() => root)
283+
.Future();
244284

245285
session
246286
.QueryOver(() => root)
@@ -271,7 +311,45 @@ public void SelectModeChildFetchDeep_SingleDbRoundtrip_Aliased()
271311
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
272312
}
273313
}
314+
315+
[Test]
316+
public void SelectModeChildFetchDeep_Aliased()
317+
{
318+
using (var session = OpenSession())
319+
{
320+
EntityComplex root = null;
321+
var list = session
322+
.QueryOver(() => root)
323+
.List();
274324

325+
session
326+
.QueryOver(() => root)
327+
.With(SelectMode.ChildFetch, () => root)
328+
.With(SelectMode.Fetch, () => root.ChildrenList)
329+
.List();
330+
331+
session
332+
.QueryOver(() => root)
333+
.With(SelectMode.ChildFetch, () => root, () => root.ChildrenList)
334+
.With(SelectMode.Fetch, () => root.ChildrenList[0].Children)
335+
.List();
336+
337+
session
338+
.QueryOver(() => root)
339+
.With(SelectMode.Skip, () => root.ChildrenList)
340+
.With(SelectMode.ChildFetch,() => root, () => root.ChildrenList[0].Children)
341+
.With(SelectMode.Fetch, () => root.ChildrenList[0].Children[0].Children)
342+
.List();
343+
344+
root = list.First(r => r.Id == _parentEntityComplexId);
345+
346+
347+
Assert.That(root?.ChildrenList, Is.Not.Null);
348+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenList));
349+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenList[0].Children));
350+
Assert.That(NHibernateUtil.IsInitialized(root?.ChildrenList[0].Children[0].Children));
351+
}
352+
}
275353

276354
[Test]
277355
public void SkipRootEntityIsNotSupported()
@@ -288,6 +366,13 @@ public void SkipRootEntityIsNotSupported()
288366
}
289367
}
290368

369+
private void SkipFutureTestIfNotSupported()
370+
{
371+
var driver = Sfi.ConnectionProvider.Driver;
372+
if (driver.SupportsMultipleQueries == false)
373+
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
374+
}
375+
291376
#region Test Setup
292377

293378
protected override HbmMapping GetMappings()

0 commit comments

Comments
 (0)