Skip to content

Commit df479da

Browse files
David EllingsworthDavid Ellingsworth
David Ellingsworth
authored and
David Ellingsworth
committed
GH2201: Add async versions of fetch loop detection tests.
1 parent 41b369e commit df479da

File tree

1 file changed

+134
-0
lines changed
  • src/NHibernate.Test/Async/NHSpecificTest/GH2201

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Collections.Generic;
13+
using System.Linq;
14+
using NHibernate.Stat;
15+
using NUnit.Framework;
16+
using NHCfg = NHibernate.Cfg;
17+
18+
namespace NHibernate.Test.NHSpecificTest.GH2201
19+
{
20+
using System.Threading.Tasks;
21+
[TestFixture]
22+
public class FixtureAsync : BugTestCase
23+
{
24+
protected override void Configure(NHCfg.Configuration configuration)
25+
{
26+
configuration.SetProperty(NHCfg.Environment.GenerateStatistics, "true");
27+
configuration.SetProperty(NHCfg.Environment.DetectFetchLoops, "false");
28+
}
29+
30+
protected override void OnTearDown()
31+
{
32+
using (var s = OpenSession())
33+
using (var tx = s.BeginTransaction())
34+
{
35+
s.Delete("from Person");
36+
37+
tx.Commit();
38+
}
39+
}
40+
41+
protected override void OnSetUp()
42+
{
43+
using (var s = OpenSession())
44+
using (var tx = s.BeginTransaction())
45+
{
46+
string[] names = { "Alice", "Bob" };
47+
48+
for (int i = 0; i < names.Length; i++)
49+
{
50+
var name = names[i];
51+
52+
Person parent = new Person()
53+
{
54+
Name = name,
55+
Details = new Detail()
56+
{
57+
Data = $"Details for ${name}"
58+
}
59+
};
60+
61+
for (int j = 1; j <= 3; j++)
62+
{
63+
Person child = new Person()
64+
{
65+
Name = $"Child ${j} of ${parent.Name}",
66+
Parent = parent,
67+
Details = new Detail()
68+
{
69+
Data = $"Details for child ${j} of ${name}"
70+
}
71+
};
72+
73+
parent.Children.Add(child);
74+
}
75+
76+
s.Save(parent);
77+
}
78+
79+
tx.Commit();
80+
}
81+
}
82+
83+
[Test]
84+
public async Task QueryOverPersonWithParentAsync()
85+
{
86+
var stats = Sfi.Statistics;
87+
88+
stats.Clear();
89+
90+
using (var s = OpenSession())
91+
using (var tx = s.BeginTransaction())
92+
{
93+
var people = await (s.QueryOver<Person>()
94+
.Fetch(SelectMode.Fetch,p => p.Parent)
95+
.Where(p => p.Parent != null)
96+
.ListAsync());
97+
98+
foreach (Person p in people)
99+
{
100+
Assert.That(p.Parent, Is.Not.Null);
101+
Assert.That(p.Parent.Details, Is.Not.Null);
102+
}
103+
104+
Assert.That(people.Count, Is.EqualTo(6));
105+
Assert.That(stats.QueryExecutionCount, Is.EqualTo(1));
106+
Assert.That(stats.EntityFetchCount, Is.EqualTo(0));
107+
Assert.That(stats.EntityLoadCount, Is.EqualTo(16));
108+
}
109+
}
110+
111+
[Test]
112+
public async Task QueryOverSinglePersonWithParentAsync()
113+
{
114+
var stats = Sfi.Statistics;
115+
116+
stats.Clear();
117+
118+
using (var s = OpenSession())
119+
using (var tx = s.BeginTransaction())
120+
{
121+
var person = await (s.QueryOver<Person>()
122+
.Where(p => p.Parent != null)
123+
.Fetch(SelectMode.Fetch, p => p.Parent)
124+
.Take(1)
125+
.SingleOrDefaultAsync());
126+
127+
Assert.That(person, Is.Not.Null);
128+
Assert.That(stats.QueryExecutionCount, Is.EqualTo(1));
129+
Assert.That(stats.EntityFetchCount, Is.EqualTo(0));
130+
Assert.That(stats.EntityLoadCount, Is.EqualTo(4));
131+
}
132+
}
133+
}
134+
}

0 commit comments

Comments
 (0)