From 102541e57b07e8728f4b3a5da4b63f95fae9ffe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericdelaporte@users.noreply.github.com> Date: Tue, 6 Feb 2024 11:38:18 +0100 Subject: [PATCH 1/3] Modernize the test case example --- .../NHSpecificTest/GH0000/Fixture.cs | 58 +++++++++---------- .../NHSpecificTest/GH0000/FixtureByCode.cs | 56 +++++++++--------- 2 files changed, 55 insertions(+), 59 deletions(-) diff --git a/src/NHibernate.Test/NHSpecificTest/GH0000/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/GH0000/Fixture.cs index 58c728c7028..a89c48bf64c 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH0000/Fixture.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH0000/Fixture.cs @@ -8,47 +8,45 @@ public class Fixture : BugTestCase { protected override void OnSetUp() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - var e1 = new Entity {Name = "Bob"}; - session.Save(e1); + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); - var e2 = new Entity {Name = "Sally"}; - session.Save(e2); + var e1 = new Entity { Name = "Bob" }; + session.Save(e1); - transaction.Commit(); - } + var e2 = new Entity { Name = "Sally" }; + session.Save(e2); + + transaction.Commit(); } protected override void OnTearDown() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - // The HQL delete does all the job inside the database without loading the entities, but it does - // not handle delete order for avoiding violating constraints if any. Use - // session.Delete("from System.Object"); - // instead if in need of having NHibernate ordering the deletes, but this will cause - // loading the entities in the session. - session.CreateQuery("delete from System.Object").ExecuteUpdate(); - - transaction.Commit(); - } + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + // The HQL delete does all the job inside the database without loading the entities, but it does + // not handle delete order for avoiding violating constraints if any. Use + // session.Delete("from System.Object"); + // instead if in need of having NHibernate ordering the deletes, but this will cause + // loading the entities in the session. + session.CreateQuery("delete from System.Object").ExecuteUpdate(); + + transaction.Commit(); } [Test] public void YourTestName() { - using (var session = OpenSession()) - using (session.BeginTransaction()) - { - var result = from e in session.Query() - where e.Name == "Bob" - select e; - - Assert.That(result.ToList(), Has.Count.EqualTo(1)); - } + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + var result = session + .Query() + .Where(e => e.Name == "Bob"); + Assert.That(result.ToList(), Has.Count.EqualTo(1)); + + transaction.Commit(); } } } diff --git a/src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs index 2bc1953e095..34758d8600e 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs @@ -30,48 +30,46 @@ protected override HbmMapping GetMappings() protected override void OnSetUp() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - var e1 = new Entity { Name = "Bob" }; - session.Save(e1); + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + var e1 = new Entity { Name = "Bob" }; + session.Save(e1); - var e2 = new Entity { Name = "Sally" }; - session.Save(e2); + var e2 = new Entity { Name = "Sally" }; + session.Save(e2); - transaction.Commit(); - } + transaction.Commit(); } protected override void OnTearDown() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - // The HQL delete does all the job inside the database without loading the entities, but it does - // not handle delete order for avoiding violating constraints if any. Use - // session.Delete("from System.Object"); - // instead if in need of having NHbernate ordering the deletes, but this will cause - // loading the entities in the session. - session.CreateQuery("delete from System.Object").ExecuteUpdate(); + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + // The HQL delete does all the job inside the database without loading the entities, but it does + // not handle delete order for avoiding violating constraints if any. Use + // session.Delete("from System.Object"); + // instead if in need of having NHbernate ordering the deletes, but this will cause + // loading the entities in the session. + session.CreateQuery("delete from System.Object").ExecuteUpdate(); - transaction.Commit(); - } + transaction.Commit(); } [Test] public void YourTestName() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - var result = from e in session.Query() - where e.Name == "Bob" - select e; + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + var result = session + .Query() + .Where(e => e.Name == "Bob"); + + Assert.That(result.ToList(), Has.Count.EqualTo(1)); - Assert.That(result.ToList(), Has.Count.EqualTo(1)); - transaction.Commit(); - } + transaction.Commit(); } } } From d8a4926f989dd85a5f27c75755202371ceef0ea4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 6 Feb 2024 10:41:02 +0000 Subject: [PATCH 2/3] Generate async files --- .../Async/NHSpecificTest/GH0000/Fixture.cs | 54 +++++++++--------- .../NHSpecificTest/GH0000/FixtureByCode.cs | 56 +++++++++---------- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH0000/Fixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH0000/Fixture.cs index 29c4aabe5cc..40ebdcc36ba 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH0000/Fixture.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH0000/Fixture.cs @@ -20,47 +20,45 @@ public class FixtureAsync : BugTestCase { protected override void OnSetUp() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - var e1 = new Entity {Name = "Bob"}; - session.Save(e1); + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); - var e2 = new Entity {Name = "Sally"}; - session.Save(e2); + var e1 = new Entity { Name = "Bob" }; + session.Save(e1); - transaction.Commit(); - } + var e2 = new Entity { Name = "Sally" }; + session.Save(e2); + + transaction.Commit(); } protected override void OnTearDown() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - // The HQL delete does all the job inside the database without loading the entities, but it does - // not handle delete order for avoiding violating constraints if any. Use - // session.Delete("from System.Object"); - // instead if in need of having NHibernate ordering the deletes, but this will cause - // loading the entities in the session. - session.CreateQuery("delete from System.Object").ExecuteUpdate(); + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + // The HQL delete does all the job inside the database without loading the entities, but it does + // not handle delete order for avoiding violating constraints if any. Use + // session.Delete("from System.Object"); + // instead if in need of having NHibernate ordering the deletes, but this will cause + // loading the entities in the session. + session.CreateQuery("delete from System.Object").ExecuteUpdate(); - transaction.Commit(); - } + transaction.Commit(); } [Test] public async Task YourTestNameAsync() { - using (var session = OpenSession()) - using (session.BeginTransaction()) - { - var result = from e in session.Query() - where e.Name == "Bob" - select e; + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + var result = session + .Query() + .Where(e => e.Name == "Bob"); + Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1)); - Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1)); - } + await (transaction.CommitAsync()); } } } diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs index 073d534694a..440f1864c05 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs @@ -42,48 +42,46 @@ protected override HbmMapping GetMappings() protected override void OnSetUp() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - var e1 = new Entity { Name = "Bob" }; - session.Save(e1); + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + var e1 = new Entity { Name = "Bob" }; + session.Save(e1); - var e2 = new Entity { Name = "Sally" }; - session.Save(e2); + var e2 = new Entity { Name = "Sally" }; + session.Save(e2); - transaction.Commit(); - } + transaction.Commit(); } protected override void OnTearDown() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - // The HQL delete does all the job inside the database without loading the entities, but it does - // not handle delete order for avoiding violating constraints if any. Use - // session.Delete("from System.Object"); - // instead if in need of having NHbernate ordering the deletes, but this will cause - // loading the entities in the session. - session.CreateQuery("delete from System.Object").ExecuteUpdate(); + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + // The HQL delete does all the job inside the database without loading the entities, but it does + // not handle delete order for avoiding violating constraints if any. Use + // session.Delete("from System.Object"); + // instead if in need of having NHbernate ordering the deletes, but this will cause + // loading the entities in the session. + session.CreateQuery("delete from System.Object").ExecuteUpdate(); - transaction.Commit(); - } + transaction.Commit(); } [Test] public async Task YourTestNameAsync() { - using (var session = OpenSession()) - using (var transaction = session.BeginTransaction()) - { - var result = from e in session.Query() - where e.Name == "Bob" - select e; + using var session = OpenSession(); + using var transaction = session.BeginTransaction(); + + var result = session + .Query() + .Where(e => e.Name == "Bob"); + + Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1)); - Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1)); - await (transaction.CommitAsync()); - } + await (transaction.CommitAsync()); } } } From 83bd7ad2b0028da07e01f227bd0f8a26192336fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericdelaporte@users.noreply.github.com> Date: Tue, 6 Feb 2024 13:00:35 +0100 Subject: [PATCH 3/3] Rename ByCodeFixture --- .../Async/NHSpecificTest/GH0000/FixtureByCode.cs | 4 ++-- src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs index 440f1864c05..0e4b4057d80 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH0000/FixtureByCode.cs @@ -21,12 +21,12 @@ namespace NHibernate.Test.NHSpecificTest.GH0000 /// Fixture using 'by code' mappings /// /// - /// This fixture is identical to except the mapping is performed + /// This fixture is identical to except the mapping is performed /// by code in the GetMappings method, and does not require the Mappings.hbm.xml file. Use this approach /// if you prefer. /// [TestFixture] - public class ByCodeFixtureAsync : TestCaseMappingByCode + public class FixtureByCodeAsync : TestCaseMappingByCode { protected override HbmMapping GetMappings() { diff --git a/src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs index 34758d8600e..a80b787db3d 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH0000/FixtureByCode.cs @@ -9,12 +9,12 @@ namespace NHibernate.Test.NHSpecificTest.GH0000 /// Fixture using 'by code' mappings /// /// - /// This fixture is identical to except the mapping is performed + /// This fixture is identical to except the mapping is performed /// by code in the GetMappings method, and does not require the Mappings.hbm.xml file. Use this approach /// if you prefer. /// [TestFixture] - public class ByCodeFixture : TestCaseMappingByCode + public class FixtureByCode : TestCaseMappingByCode { protected override HbmMapping GetMappings() {