Skip to content

Commit 8b71b85

Browse files
Modernize the test case example (#3484)
1 parent cd2e8ea commit 8b71b85

File tree

4 files changed

+112
-120
lines changed

4 files changed

+112
-120
lines changed

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

+26-28
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

+29-31
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace NHibernate.Test.NHSpecificTest.GH0000
2121
/// Fixture using 'by code' mappings
2222
/// </summary>
2323
/// <remarks>
24-
/// This fixture is identical to <see cref="FixtureAsync" /> except the <see cref="Entity" /> mapping is performed
24+
/// This fixture is identical to <see cref="FixtureAsync" /> except the <see cref="Entity" /> mapping is performed
2525
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
2626
/// if you prefer.
2727
/// </remarks>
2828
[TestFixture]
29-
public class ByCodeFixtureAsync : TestCaseMappingByCode
29+
public class FixtureByCodeAsync : TestCaseMappingByCode
3030
{
3131
protected override HbmMapping GetMappings()
3232
{
@@ -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
}

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

+28-30
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,45 @@ public class Fixture : BugTestCase
88
{
99
protected override void OnSetUp()
1010
{
11-
using (var session = OpenSession())
12-
using (var transaction = session.BeginTransaction())
13-
{
14-
var e1 = new Entity {Name = "Bob"};
15-
session.Save(e1);
11+
using var session = OpenSession();
12+
using var transaction = session.BeginTransaction();
1613

17-
var e2 = new Entity {Name = "Sally"};
18-
session.Save(e2);
14+
var e1 = new Entity { Name = "Bob" };
15+
session.Save(e1);
1916

20-
transaction.Commit();
21-
}
17+
var e2 = new Entity { Name = "Sally" };
18+
session.Save(e2);
19+
20+
transaction.Commit();
2221
}
2322

2423
protected override void OnTearDown()
2524
{
26-
using (var session = OpenSession())
27-
using (var transaction = session.BeginTransaction())
28-
{
29-
// The HQL delete does all the job inside the database without loading the entities, but it does
30-
// not handle delete order for avoiding violating constraints if any. Use
31-
// session.Delete("from System.Object");
32-
// instead if in need of having NHibernate ordering the deletes, but this will cause
33-
// loading the entities in the session.
34-
session.CreateQuery("delete from System.Object").ExecuteUpdate();
35-
36-
transaction.Commit();
37-
}
25+
using var session = OpenSession();
26+
using var transaction = session.BeginTransaction();
27+
28+
// The HQL delete does all the job inside the database without loading the entities, but it does
29+
// not handle delete order for avoiding violating constraints if any. Use
30+
// session.Delete("from System.Object");
31+
// instead if in need of having NHibernate ordering the deletes, but this will cause
32+
// loading the entities in the session.
33+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
34+
35+
transaction.Commit();
3836
}
3937

4038
[Test]
4139
public void YourTestName()
4240
{
43-
using (var session = OpenSession())
44-
using (session.BeginTransaction())
45-
{
46-
var result = from e in session.Query<Entity>()
47-
where e.Name == "Bob"
48-
select e;
49-
50-
Assert.That(result.ToList(), Has.Count.EqualTo(1));
51-
}
41+
using var session = OpenSession();
42+
using var transaction = session.BeginTransaction();
43+
44+
var result = session
45+
.Query<Entity>()
46+
.Where(e => e.Name == "Bob");
47+
Assert.That(result.ToList(), Has.Count.EqualTo(1));
48+
49+
transaction.Commit();
5250
}
5351
}
5452
}

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

+29-31
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ namespace NHibernate.Test.NHSpecificTest.GH0000
99
/// Fixture using 'by code' mappings
1010
/// </summary>
1111
/// <remarks>
12-
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entity" /> mapping is performed
12+
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entity" /> mapping is performed
1313
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
1414
/// if you prefer.
1515
/// </remarks>
1616
[TestFixture]
17-
public class ByCodeFixture : TestCaseMappingByCode
17+
public class FixtureByCode : TestCaseMappingByCode
1818
{
1919
protected override HbmMapping GetMappings()
2020
{
@@ -30,48 +30,46 @@ protected override HbmMapping GetMappings()
3030

3131
protected override void OnSetUp()
3232
{
33-
using (var session = OpenSession())
34-
using (var transaction = session.BeginTransaction())
35-
{
36-
var e1 = new Entity { Name = "Bob" };
37-
session.Save(e1);
33+
using var session = OpenSession();
34+
using var transaction = session.BeginTransaction();
35+
36+
var e1 = new Entity { Name = "Bob" };
37+
session.Save(e1);
3838

39-
var e2 = new Entity { Name = "Sally" };
40-
session.Save(e2);
39+
var e2 = new Entity { Name = "Sally" };
40+
session.Save(e2);
4141

42-
transaction.Commit();
43-
}
42+
transaction.Commit();
4443
}
4544

4645
protected override void OnTearDown()
4746
{
48-
using (var session = OpenSession())
49-
using (var transaction = session.BeginTransaction())
50-
{
51-
// The HQL delete does all the job inside the database without loading the entities, but it does
52-
// not handle delete order for avoiding violating constraints if any. Use
53-
// session.Delete("from System.Object");
54-
// instead if in need of having NHbernate ordering the deletes, but this will cause
55-
// loading the entities in the session.
56-
session.CreateQuery("delete from System.Object").ExecuteUpdate();
47+
using var session = OpenSession();
48+
using var transaction = session.BeginTransaction();
49+
50+
// The HQL delete does all the job inside the database without loading the entities, but it does
51+
// not handle delete order for avoiding violating constraints if any. Use
52+
// session.Delete("from System.Object");
53+
// instead if in need of having NHbernate ordering the deletes, but this will cause
54+
// loading the entities in the session.
55+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
5756

58-
transaction.Commit();
59-
}
57+
transaction.Commit();
6058
}
6159

6260
[Test]
6361
public void YourTestName()
6462
{
65-
using (var session = OpenSession())
66-
using (var transaction = session.BeginTransaction())
67-
{
68-
var result = from e in session.Query<Entity>()
69-
where e.Name == "Bob"
70-
select e;
63+
using var session = OpenSession();
64+
using var transaction = session.BeginTransaction();
65+
66+
var result = session
67+
.Query<Entity>()
68+
.Where(e => e.Name == "Bob");
69+
70+
Assert.That(result.ToList(), Has.Count.EqualTo(1));
7171

72-
Assert.That(result.ToList(), Has.Count.EqualTo(1));
73-
transaction.Commit();
74-
}
72+
transaction.Commit();
7573
}
7674
}
7775
}

0 commit comments

Comments
 (0)