Skip to content

Commit b845845

Browse files
Generate async files
1 parent 371fc87 commit b845845

File tree

1 file changed

+150
-0
lines changed
  • src/NHibernate.Test/Async/NHSpecificTest/GH3290

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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 NHibernate.Cfg;
13+
using NHibernate.Cfg.MappingSchema;
14+
using NHibernate.Mapping.ByCode;
15+
using NHibernate.Transform;
16+
using NUnit.Framework;
17+
18+
namespace NHibernate.Test.NHSpecificTest.GH3290
19+
{
20+
using System.Threading.Tasks;
21+
[TestFixture(true)]
22+
[TestFixture(false)]
23+
public class FixtureAsync : TestCaseMappingByCode
24+
{
25+
private readonly bool _detectFetchLoops;
26+
27+
public FixtureAsync(bool detectFetchLoops)
28+
{
29+
_detectFetchLoops = detectFetchLoops;
30+
}
31+
32+
protected override HbmMapping GetMappings()
33+
{
34+
var mapper = new ModelMapper();
35+
mapper.Class<Entity>(rc =>
36+
{
37+
rc.Id(x => x.Id, map => map.Generator(Generators.GuidComb));
38+
39+
rc.Property(
40+
x => x.Name
41+
);
42+
43+
rc.Set(
44+
x => x.Children,
45+
v =>
46+
{
47+
v.Table("EntityToEntity");
48+
v.Cascade(Mapping.ByCode.Cascade.None);
49+
v.Inverse(true);
50+
v.Key(x =>
51+
{
52+
x.Column("ParentId");
53+
x.NotNullable(true);
54+
});
55+
v.Lazy(CollectionLazy.Lazy);
56+
v.Fetch(CollectionFetchMode.Join);
57+
},
58+
h => h.ManyToMany(m => m.Column("ChildId"))
59+
);
60+
61+
rc.Set(
62+
x => x.Parents,
63+
v =>
64+
{
65+
v.Table("EntityToEntity");
66+
v.Cascade(Mapping.ByCode.Cascade.All);
67+
68+
v.Key(x =>
69+
{
70+
x.Column("ChildId");
71+
x.NotNullable(true);
72+
});
73+
v.Lazy(CollectionLazy.Lazy);
74+
v.Fetch(CollectionFetchMode.Join);
75+
},
76+
h => h.ManyToMany(m => m.Column("ParentId"))
77+
);
78+
});
79+
80+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
81+
}
82+
83+
protected override void Configure(Configuration configuration)
84+
{
85+
if (_detectFetchLoops)
86+
return;
87+
88+
configuration.SetProperty(Environment.DetectFetchLoops, "false");
89+
configuration.SetProperty(Environment.MaxFetchDepth, "2");
90+
}
91+
92+
protected override void OnSetUp()
93+
{
94+
using var session = OpenSession();
95+
using var transaction = session.BeginTransaction();
96+
97+
var person = new Entity
98+
{
99+
Name = "pers",
100+
Parents = new HashSet<Entity>()
101+
};
102+
session.Save(person);
103+
var job = new Entity
104+
{
105+
Name = "job",
106+
Children = new HashSet<Entity>()
107+
};
108+
session.Save(job);
109+
110+
job.Children.Add(person);
111+
person.Parents.Add(job);
112+
113+
transaction.Commit();
114+
}
115+
116+
protected override void OnTearDown()
117+
{
118+
using var session = OpenSession();
119+
using var transaction = session.BeginTransaction();
120+
121+
session.CreateSQLQuery("delete from EntityToEntity").ExecuteUpdate();
122+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
123+
124+
transaction.Commit();
125+
}
126+
127+
[Test]
128+
public async Task QueryWithFetchAsync()
129+
{
130+
using var session = OpenSession();
131+
using var _ = session.BeginTransaction();
132+
133+
var all = await (session
134+
.QueryOver<Entity>()
135+
.Fetch(SelectMode.Fetch, x => x.Children)
136+
.Fetch(SelectMode.Fetch, x => x.Parents)
137+
.TransformUsing(Transformers.DistinctRootEntity)
138+
.ListAsync());
139+
140+
foreach (var entity in all)
141+
{
142+
var isPerson = entity.Name == "pers";
143+
if (isPerson)
144+
Assert.That(entity.Parents, Has.Count.EqualTo(1), "Person's job not found or non-unique.");
145+
else
146+
Assert.That(entity.Children, Has.Count.EqualTo(1), "Job's employee not found or non-unique.");
147+
}
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)