Skip to content

Commit def6ef8

Browse files
Generate async files
1 parent 62f4331 commit def6ef8

File tree

1 file changed

+169
-0
lines changed
  • src/NHibernate.Test/Async/NHSpecificTest/GH3334

1 file changed

+169
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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.Collections.Generic;
12+
using System.Runtime.CompilerServices;
13+
using NUnit.Framework;
14+
15+
namespace NHibernate.Test.NHSpecificTest.GH3334
16+
{
17+
using System.Threading.Tasks;
18+
[TestFixture]
19+
public class FixtureAsync : BugTestCase
20+
{
21+
[OneTimeSetUp]
22+
public void OneTimeSetUp()
23+
{
24+
using (var session = OpenSession())
25+
using (var t = session.BeginTransaction())
26+
{
27+
var parent = new Entity
28+
{
29+
Name = "Parent1",
30+
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "GrandChild" } } }
31+
};
32+
session.Save(parent);
33+
parent = new Entity
34+
{
35+
Name = "Parent2",
36+
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "XGrandChild" } } }
37+
};
38+
var other = new OtherEntity { Name = "ABC", Entities = {parent}};
39+
parent.OtherEntity = other;
40+
session.Save(parent);
41+
session.Save(other);
42+
t.Commit();
43+
}
44+
45+
Sfi.Statistics.IsStatisticsEnabled = true;
46+
}
47+
48+
[OneTimeTearDown]
49+
public void OneTimeTearDown()
50+
{
51+
Sfi.Statistics.IsStatisticsEnabled = false;
52+
53+
using var session = OpenSession();
54+
using var transaction = session.BeginTransaction();
55+
56+
session.CreateQuery("delete from ChildEntity").ExecuteUpdate();
57+
session.CreateQuery("delete from GrandChildEntity").ExecuteUpdate();
58+
session.CreateQuery("delete from Entity").ExecuteUpdate();
59+
session.CreateQuery("delete from OtherEntity").ExecuteUpdate();
60+
61+
transaction.Commit();
62+
}
63+
64+
public static IEnumerable<TestCase> GetNoExceptionOnExecuteQueryTestCases()
65+
{
66+
/* does not work because of inner join or theta join created for many-to-one
67+
@"
68+
SELECT ROOT
69+
FROM Entity AS ROOT
70+
WHERE
71+
EXISTS
72+
(FROM ELEMENTS(ROOT.Children) AS child
73+
WHERE
74+
child.Child.Name like 'G%'
75+
OR ROOT.OtherEntity.Name like 'A%'
76+
)");*/
77+
78+
yield return new("Basic Elements case 1 FoundViaGrandChildG", @"
79+
SELECT ROOT
80+
FROM Entity AS ROOT
81+
WHERE
82+
EXISTS
83+
(FROM ELEMENTS(ROOT.Children) AS child
84+
LEFT JOIN child.Child AS grandChild
85+
WHERE
86+
grandChild.Name like 'G%'
87+
)");
88+
yield return new("Basic Elements case 2 FoundViaOtherEntityA", @"
89+
SELECT ROOT
90+
FROM Entity AS ROOT
91+
WHERE
92+
EXISTS
93+
(FROM ELEMENTS(ROOT.OtherEntity) AS otherEntity
94+
WHERE
95+
otherEntity.Name like 'A%'
96+
)");
97+
yield return new("HQL Elements FoundViaGrandChildG", @"
98+
SELECT ROOT
99+
FROM Entity AS ROOT
100+
WHERE
101+
EXISTS
102+
(FROM ELEMENTS(ROOT.Children) AS child
103+
LEFT JOIN child.Child AS grandChild
104+
LEFT JOIN ROOT.OtherEntity AS otherEntity
105+
WHERE
106+
grandChild.Name like 'G%'
107+
OR otherEntity.Name like 'G%'
108+
)");
109+
yield return new("HQL Elements FoundViaOtherEntityA", @"
110+
SELECT ROOT
111+
FROM Entity AS ROOT
112+
WHERE
113+
EXISTS
114+
(FROM ELEMENTS(ROOT.Children) AS child
115+
LEFT JOIN child.Child AS grandChild
116+
LEFT JOIN ROOT.OtherEntity AS otherEntity
117+
WHERE
118+
grandChild.Name like 'A%'
119+
OR otherEntity.Name like 'A%'
120+
)");
121+
yield return new("HQL Entity FoundViaGrandChildG", @"
122+
SELECT ROOT
123+
FROM Entity AS ROOT
124+
WHERE
125+
EXISTS
126+
(FROM ChildEntity AS child
127+
LEFT JOIN child.Child AS grandChild
128+
LEFT JOIN ROOT.OtherEntity AS otherEntity
129+
WHERE
130+
child.Parent = ROOT
131+
AND (
132+
grandChild.Name like 'G%'
133+
OR otherEntity.Name like 'G%'
134+
)
135+
)");
136+
yield return new("HQL Entity FoundViaOtherEntityA", @"
137+
SELECT ROOT
138+
FROM Entity AS ROOT
139+
WHERE
140+
EXISTS
141+
(FROM ChildEntity AS child
142+
LEFT JOIN child.Child AS grandChild
143+
LEFT JOIN ROOT.OtherEntity AS otherEntity
144+
WHERE
145+
child.Parent = ROOT
146+
AND (
147+
grandChild.Name like 'A%'
148+
OR otherEntity.Name like 'A%'
149+
)
150+
)");
151+
}
152+
153+
[Test, TestCaseSource(nameof(GetNoExceptionOnExecuteQueryTestCases))]
154+
public async Task NoExceptionOnExecuteQueryAsync(TestCase testCase)
155+
{
156+
using var session = OpenSession();
157+
using var _ = session.BeginTransaction();
158+
159+
var q = session.CreateQuery(testCase.Hql);
160+
Assert.AreEqual(1, (await (q.ListAsync())).Count);
161+
}
162+
163+
protected override bool CheckDatabaseWasCleaned()
164+
{
165+
// same set of objects for each test
166+
return true;
167+
}
168+
}
169+
}

0 commit comments

Comments
 (0)