Skip to content

Commit 071923a

Browse files
github-actions[bot]hazzik
authored andcommitted
Generate async files
1 parent 5d7abf7 commit 071923a

File tree

2 files changed

+289
-0
lines changed

2 files changed

+289
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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.Linq;
12+
using NHibernate.Cfg.MappingSchema;
13+
using NHibernate.DomainModel;
14+
using NHibernate.Mapping.ByCode;
15+
using NUnit.Framework;
16+
using NHibernate.Linq;
17+
18+
namespace NHibernate.Test.NHSpecificTest.GH3363
19+
{
20+
using System.Threading.Tasks;
21+
/// <summary>
22+
/// Fixture using 'by code' mappings
23+
/// </summary>
24+
/// <remarks>
25+
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entities" /> mapping is performed
26+
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
27+
/// if you prefer.
28+
/// </remarks>
29+
[TestFixture]
30+
public class ByCodeFixtureAsync : TestCaseMappingByCode
31+
{
32+
protected override HbmMapping GetMappings()
33+
{
34+
var mapper = new ModelMapper();
35+
36+
mapper.Class<Mother>(rc =>
37+
{
38+
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
39+
rc.Property(x => x.Name);
40+
rc.Discriminator(x => x.Column("kind"));
41+
});
42+
mapper.Subclass<Child1>(rc =>
43+
{
44+
rc.Property(x => x.Name);
45+
rc.ManyToOne(x => x.Thing, m =>{
46+
m.NotFound(NotFoundMode.Ignore);
47+
m.Column("thingId");
48+
});
49+
rc.DiscriminatorValue(1);
50+
});
51+
mapper.Subclass<Child2>(rc =>
52+
{
53+
rc.Property(x => x.Name);
54+
rc.ManyToOne(x => x.Thing, m => {
55+
m.NotFound(NotFoundMode.Ignore);
56+
m.Column("thingId");
57+
});
58+
rc.DiscriminatorValue(2);
59+
});
60+
mapper.Class<Thing1>(rc =>
61+
{
62+
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned));
63+
rc.Property(x => x.Name);
64+
65+
});
66+
mapper.Class<Thing2>(rc =>
67+
{
68+
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned));
69+
rc.Property(x => x.Name);
70+
71+
});
72+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
73+
}
74+
75+
protected override void OnSetUp()
76+
{
77+
using (var session = OpenSession())
78+
using (var transaction = session.BeginTransaction())
79+
{
80+
var t1 = new Thing1() { Name = "don't care",Id="00001" };
81+
session.Save(t1);
82+
var t2 = new Thing2() { Name = "look for this",Id="00002" };
83+
session.Save(t2);
84+
var child1 = new Child1 { Name = "Child1",Thing=t1 };
85+
session.Save(child1);
86+
var child2 = new Child2 { Name = "Child1", Thing = t2 };
87+
session.Save(child2);
88+
transaction.Commit();
89+
}
90+
}
91+
92+
protected override void OnTearDown()
93+
{
94+
using (var session = OpenSession())
95+
using (var transaction = session.BeginTransaction())
96+
{
97+
// The HQL delete does all the job inside the database without loading the entities, but it does
98+
// not handle delete order for avoiding violating constraints if any. Use
99+
// session.Delete("from System.Object");
100+
// instead if in need of having NHbernate ordering the deletes, but this will cause
101+
// loading the entities in the session.
102+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
103+
104+
transaction.Commit();
105+
}
106+
}
107+
108+
[Test]
109+
public async Task LookForThingOfTypeThing1Async()
110+
{
111+
using (var session = OpenSession())
112+
using (var transaction = session.BeginTransaction())
113+
{
114+
/*
115+
* wrong statement created
116+
* select mother0_.Id as id1_0_, mother0_.Name as name3_0_,
117+
mother0_.thingId as thingid4_0_, mother0_.kind as kind2_0_ from Mother mother0_
118+
left outer join Thing2 thing2x1_ on
119+
mother0_.thingId=thing2x1_.Id where mother0_.kind='1' and thing2x1_.Id=?"
120+
*
121+
*/
122+
123+
var result = await (session.Query<Mother>().Where(k => k is Child1 && (k as Child1).Thing.Id == "00001").ToListAsync());
124+
125+
Assert.That(result, Has.Count.EqualTo(1));
126+
await (transaction.CommitAsync());
127+
}
128+
}
129+
}
130+
131+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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.Linq;
12+
using NHibernate.Cfg.MappingSchema;
13+
using NHibernate.DomainModel;
14+
using NHibernate.Mapping.ByCode;
15+
using NUnit.Framework;
16+
using NHibernate.Linq;
17+
18+
namespace NHibernate.Test.NHSpecificTest.NH3363
19+
{
20+
using System.Threading.Tasks;
21+
/// <summary>
22+
/// Fixture using 'by code' mappings
23+
/// </summary>
24+
/// <remarks>
25+
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entities" /> mapping is performed
26+
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
27+
/// if you prefer.
28+
/// </remarks>
29+
[TestFixture]
30+
public class ByCodeFixtureAsync : TestCaseMappingByCode
31+
{
32+
protected override HbmMapping GetMappings()
33+
{
34+
var mapper = new ModelMapper();
35+
36+
mapper.Class<Mother>(rc =>
37+
{
38+
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
39+
rc.Property(x => x.Name);
40+
rc.Discriminator(x => x.Column("kind"));
41+
});
42+
mapper.Subclass<Child1>(rc =>
43+
{
44+
rc.Property(x => x.Name);
45+
rc.ManyToOne(x => x.Thing, m =>{
46+
m.NotFound(NotFoundMode.Ignore);
47+
m.Column("thingId");
48+
});
49+
rc.DiscriminatorValue(1);
50+
});
51+
mapper.Subclass<Child2>(rc =>
52+
{
53+
rc.Property(x => x.Name);
54+
rc.ManyToOne(x => x.Thing, m => {
55+
m.NotFound(NotFoundMode.Ignore);
56+
m.Column("thingId");
57+
});
58+
rc.DiscriminatorValue(2);
59+
});
60+
mapper.Class<Thing1>(rc =>
61+
{
62+
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned));
63+
rc.Property(x => x.Name);
64+
65+
});
66+
mapper.Class<Thing2>(rc =>
67+
{
68+
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned));
69+
rc.Property(x => x.Name);
70+
71+
});
72+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
73+
}
74+
75+
protected override void OnSetUp()
76+
{
77+
using (var session = OpenSession())
78+
using (var transaction = session.BeginTransaction())
79+
{
80+
var t1 = new Thing1() { Name = "don't care",Id="00001" };
81+
session.Save(t1);
82+
var t2 = new Thing2() { Name = "look for this",Id="00002" };
83+
session.Save(t2);
84+
var child1 = new Child1 { Name = "Child1",Thing=t1 };
85+
session.Save(child1);
86+
var child2 = new Child2 { Name = "Child1", Thing = t2 };
87+
session.Save(child2);
88+
transaction.Commit();
89+
}
90+
}
91+
92+
protected override void OnTearDown()
93+
{
94+
using (var session = OpenSession())
95+
using (var transaction = session.BeginTransaction())
96+
{
97+
// The HQL delete does all the job inside the database without loading the entities, but it does
98+
// not handle delete order for avoiding violating constraints if any. Use
99+
// session.Delete("from System.Object");
100+
// instead if in need of having NHbernate ordering the deletes, but this will cause
101+
// loading the entities in the session.
102+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
103+
104+
transaction.Commit();
105+
}
106+
}
107+
108+
[Test]
109+
public async Task LookForThingOfTypeThing2Async()
110+
{
111+
using (var session = OpenSession())
112+
using (var transaction = session.BeginTransaction())
113+
{
114+
var result = await (session.Query<Mother>().Where(k=>k is Child2 && (k as Child2).Thing.Id == "00002").ToListAsync());
115+
116+
Assert.That(result, Has.Count.EqualTo(1));
117+
await (transaction.CommitAsync());
118+
}
119+
}
120+
[Test]
121+
public async Task LookForThingOfTypeThing1Async()
122+
{
123+
using (var session = OpenSession())
124+
using (var transaction = session.BeginTransaction())
125+
{
126+
var oftype = await (session.Query<Mother>().Where(k => k is Child1).ToListAsync());
127+
Assert.That(oftype, Has.Count.EqualTo(1));
128+
Assert.That((oftype[0] as Child1).Thing, Is.Not.Null);
129+
/*
130+
* wrong statement created
131+
* select mother0_.Id as id1_0_, mother0_.Name as name3_0_,
132+
mother0_.thingId as thingid4_0_, mother0_.kind as kind2_0_ from Mother mother0_
133+
left outer join Thing2 thing2x1_ on
134+
mother0_.thingId=thing2x1_.Id where mother0_.kind='1' and thing2x1_.Id=?"
135+
*
136+
*/
137+
138+
var result = await (session.Query<Mother>().Where(k => k is Child1 && (k as Child1).Thing.Id == "00001").ToListAsync());
139+
140+
Assert.That(result, Has.Count.EqualTo(1));
141+
await (transaction.CommitAsync());
142+
}
143+
}
144+
[Test]
145+
public async Task LookForManyToOneByDescrAsync()
146+
{
147+
using (var session = OpenSession())
148+
using (var transaction = session.BeginTransaction())
149+
{
150+
var result = await (session.Query<Mother>().Where(k => k is Child2 && (k as Child2).Thing.Name == "look for this").ToListAsync());
151+
152+
Assert.That(result, Has.Count.EqualTo(1));
153+
await (transaction.CommitAsync());
154+
}
155+
}
156+
}
157+
158+
}

0 commit comments

Comments
 (0)