Skip to content

Commit 102541e

Browse files
Modernize the test case example
1 parent a958ff1 commit 102541e

File tree

2 files changed

+55
-59
lines changed

2 files changed

+55
-59
lines changed

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

Lines changed: 28 additions & 30 deletions
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

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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)