Skip to content

Commit d8a4926

Browse files
Generate async files
1 parent 102541e commit d8a4926

File tree

2 files changed

+53
-57
lines changed

2 files changed

+53
-57
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH0000/Fixture.cs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,45 @@ public class FixtureAsync : BugTestCase
2020
{
2121
protected override void OnSetUp()
2222
{
23-
using (var session = OpenSession())
24-
using (var transaction = session.BeginTransaction())
25-
{
26-
var e1 = new Entity {Name = "Bob"};
27-
session.Save(e1);
23+
using var session = OpenSession();
24+
using var transaction = session.BeginTransaction();
2825

29-
var e2 = new Entity {Name = "Sally"};
30-
session.Save(e2);
26+
var e1 = new Entity { Name = "Bob" };
27+
session.Save(e1);
3128

32-
transaction.Commit();
33-
}
29+
var e2 = new Entity { Name = "Sally" };
30+
session.Save(e2);
31+
32+
transaction.Commit();
3433
}
3534

3635
protected override void OnTearDown()
3736
{
38-
using (var session = OpenSession())
39-
using (var transaction = session.BeginTransaction())
40-
{
41-
// The HQL delete does all the job inside the database without loading the entities, but it does
42-
// not handle delete order for avoiding violating constraints if any. Use
43-
// session.Delete("from System.Object");
44-
// instead if in need of having NHibernate ordering the deletes, but this will cause
45-
// loading the entities in the session.
46-
session.CreateQuery("delete from System.Object").ExecuteUpdate();
37+
using var session = OpenSession();
38+
using var transaction = session.BeginTransaction();
39+
40+
// The HQL delete does all the job inside the database without loading the entities, but it does
41+
// not handle delete order for avoiding violating constraints if any. Use
42+
// session.Delete("from System.Object");
43+
// instead if in need of having NHibernate ordering the deletes, but this will cause
44+
// loading the entities in the session.
45+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
4746

48-
transaction.Commit();
49-
}
47+
transaction.Commit();
5048
}
5149

5250
[Test]
5351
public async Task YourTestNameAsync()
5452
{
55-
using (var session = OpenSession())
56-
using (session.BeginTransaction())
57-
{
58-
var result = from e in session.Query<Entity>()
59-
where e.Name == "Bob"
60-
select e;
53+
using var session = OpenSession();
54+
using var transaction = session.BeginTransaction();
55+
56+
var result = session
57+
.Query<Entity>()
58+
.Where(e => e.Name == "Bob");
59+
Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
6160

62-
Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
63-
}
61+
await (transaction.CommitAsync());
6462
}
6563
}
6664
}

src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,48 +42,46 @@ protected override HbmMapping GetMappings()
4242

4343
protected override void OnSetUp()
4444
{
45-
using (var session = OpenSession())
46-
using (var transaction = session.BeginTransaction())
47-
{
48-
var e1 = new Entity { Name = "Bob" };
49-
session.Save(e1);
45+
using var session = OpenSession();
46+
using var transaction = session.BeginTransaction();
47+
48+
var e1 = new Entity { Name = "Bob" };
49+
session.Save(e1);
5050

51-
var e2 = new Entity { Name = "Sally" };
52-
session.Save(e2);
51+
var e2 = new Entity { Name = "Sally" };
52+
session.Save(e2);
5353

54-
transaction.Commit();
55-
}
54+
transaction.Commit();
5655
}
5756

5857
protected override void OnTearDown()
5958
{
60-
using (var session = OpenSession())
61-
using (var transaction = session.BeginTransaction())
62-
{
63-
// The HQL delete does all the job inside the database without loading the entities, but it does
64-
// not handle delete order for avoiding violating constraints if any. Use
65-
// session.Delete("from System.Object");
66-
// instead if in need of having NHbernate ordering the deletes, but this will cause
67-
// loading the entities in the session.
68-
session.CreateQuery("delete from System.Object").ExecuteUpdate();
59+
using var session = OpenSession();
60+
using var transaction = session.BeginTransaction();
61+
62+
// The HQL delete does all the job inside the database without loading the entities, but it does
63+
// not handle delete order for avoiding violating constraints if any. Use
64+
// session.Delete("from System.Object");
65+
// instead if in need of having NHbernate ordering the deletes, but this will cause
66+
// loading the entities in the session.
67+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
6968

70-
transaction.Commit();
71-
}
69+
transaction.Commit();
7270
}
7371

7472
[Test]
7573
public async Task YourTestNameAsync()
7674
{
77-
using (var session = OpenSession())
78-
using (var transaction = session.BeginTransaction())
79-
{
80-
var result = from e in session.Query<Entity>()
81-
where e.Name == "Bob"
82-
select e;
75+
using var session = OpenSession();
76+
using var transaction = session.BeginTransaction();
77+
78+
var result = session
79+
.Query<Entity>()
80+
.Where(e => e.Name == "Bob");
81+
82+
Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
8383

84-
Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
85-
await (transaction.CommitAsync());
86-
}
84+
await (transaction.CommitAsync());
8785
}
8886
}
8987
}

0 commit comments

Comments
 (0)