From 24e3b823c70029e664c94889567a7b3ffe39dd05 Mon Sep 17 00:00:00 2001 From: DmitryMak Date: Thu, 2 May 2024 22:20:17 -0700 Subject: [PATCH 1/7] Add files via upload --- .../NHSpecificTest/GH3539/CardInfo.cs | 47 ++++++++++ .../GH3539/ImmutableComponentTest.cs | 93 +++++++++++++++++++ .../NHSpecificTest/GH3539/Person.cs | 35 +++++++ .../NHSpecificTest/GH3539/Person.hbm.xml | 21 +++++ 4 files changed, 196 insertions(+) create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3539/Person.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3539/Person.hbm.xml diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs new file mode 100644 index 0000000000..993e3d5bda --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace NHibernate.Test.NHSpecificTest.GH3539; + +public class CardInfo +{ + private readonly ISet _oldCards; + + protected CardInfo() { } + + public CardInfo(params string[] cards) + { + _oldCards = cards.ToHashSet(); + } + + public virtual ISet GetCardsCopy() + { + return _oldCards.ToHashSet(); + } + + public override bool Equals(object obj) + { + if (obj is null) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + var other = (CardInfo) obj; + return _oldCards.SetEquals(other._oldCards); + } + + public override int GetHashCode() + { + var hashCode = new HashCode(); + hashCode.Add(_oldCards); + return hashCode.ToHashCode(); + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs new file mode 100644 index 0000000000..ef8bf637d8 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs @@ -0,0 +1,93 @@ +using System; +using System.IO; +using System.Reflection; +using NHibernate.Cfg; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH3539 +{ + [TestFixture] + public class ImmutableComponentTest : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override string[] Mappings + { + get { return Array.Empty(); } + } + + protected override void Configure(Configuration configuration) + { + using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( + "NHibernate.Test.NHSpecificTest.GH3539.Person.hbm.xml")) + { + using (StreamReader reader = new StreamReader(stream)) + { + string mapping = reader.ReadToEnd(); + + configuration.AddXml(mapping); + configuration.SetProperty(Cfg.Environment.GenerateStatistics, "true"); + } + } + } + + protected override void OnTearDown() + { + using (ISession s = Sfi.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from Person"); + t.Commit(); + } + + base.OnTearDown(); + } + + [Test] + public void TestComponent() + { + int personId; + using (ISession s = Sfi.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + var person = new Person(age: 20) + { + CardInfo = new("card1", "card2") + }; + s.Save(person); + t.Commit(); + s.Flush(); + personId = person.Id; + } + + using (ISession s = Sfi.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + var restored = s.Get(personId); + + var oldCardInfo = restored.CardInfo; + + Assert.That(oldCardInfo.GetCardsCopy().Contains("card1")); + Assert.That(oldCardInfo.GetCardsCopy().Contains("card2")); + + var newCardInfo = new CardInfo("card1", "card2"); + + Assert.That(oldCardInfo.Equals(newCardInfo), Is.True); + + restored.CardInfo = newCardInfo; + + // Expected behaviour: + // + // At this point there should be no DML statements because newCardInfo + // is the same as the old one. But NHibernate will generate DELETE + // followed by 2 INSERT into OldCards table. I'm not sure how to fail + // an assertion when an unexpected DML is issued. + + t.Commit(); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/Person.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/Person.cs new file mode 100644 index 0000000000..aa3ceee5cb --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/Person.cs @@ -0,0 +1,35 @@ +namespace NHibernate.Test.NHSpecificTest.GH3539 +{ + public class Person + { + private int _id; + private int _age; + private CardInfo _cardInfo; + + protected Person() { } + + public Person(int age) + { + _cardInfo = new(); + _age = age; + } + + public virtual int Id + { + get { return _id; } + set { _id = value; } + } + + public virtual int Age + { + get { return _age; } + set { _age = value; } + } + + public virtual CardInfo CardInfo + { + get { return _cardInfo; } + set { _cardInfo = value; } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/Person.hbm.xml b/src/NHibernate.Test/NHSpecificTest/GH3539/Person.hbm.xml new file mode 100644 index 0000000000..a153459cc0 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/Person.hbm.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + From 0fb75ad8b8a3e5bcecd1213010ea72371b135708 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 3 May 2024 05:33:41 +0000 Subject: [PATCH 2/7] Generate async files --- .../GH3539/ImmutableComponentTest.cs | 104 ++++++++++++++++++ .../NHSpecificTest/GH3539/CardInfo.cs | 24 ++-- .../GH3539/ImmutableComponentTest.cs | 48 ++++---- .../NHSpecificTest/GH3539/Person.cs | 14 +-- 4 files changed, 147 insertions(+), 43 deletions(-) create mode 100644 src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs new file mode 100644 index 0000000000..05529b5878 --- /dev/null +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by AsyncGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +using System; +using System.IO; +using System.Reflection; +using NHibernate.Cfg; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH3539 +{ + using System.Threading.Tasks; + [TestFixture] + public class ImmutableComponentTestAsync : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override string[] Mappings + { + get { return Array.Empty(); } + } + + protected override void Configure(Configuration configuration) + { + using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( + "NHibernate.Test.NHSpecificTest.GH3539.Person.hbm.xml")) + { + using (StreamReader reader = new StreamReader(stream)) + { + string mapping = reader.ReadToEnd(); + + configuration.AddXml(mapping); + configuration.SetProperty(Cfg.Environment.GenerateStatistics, "true"); + } + } + } + + protected override void OnTearDown() + { + using (ISession s = Sfi.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from Person"); + t.Commit(); + } + + base.OnTearDown(); + } + + [Test] + public async Task TestComponentAsync() + { + int personId; + using (ISession s = Sfi.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + var person = new Person(age: 20) + { + CardInfo = new("card1", "card2") + }; + await (s.SaveAsync(person)); + await (t.CommitAsync()); + await (s.FlushAsync()); + personId = person.Id; + } + + using (ISession s = Sfi.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + var restored = await (s.GetAsync(personId)); + + var oldCardInfo = restored.CardInfo; + + Assert.That(oldCardInfo.GetCardsCopy().Contains("card1")); + Assert.That(oldCardInfo.GetCardsCopy().Contains("card2")); + + var newCardInfo = new CardInfo("card1", "card2"); + + Assert.That(oldCardInfo.Equals(newCardInfo), Is.True); + + restored.CardInfo = newCardInfo; + + // Expected behaviour: + // + // At this point there should be no DML statements because newCardInfo + // is the same as the old one. But NHibernate will generate DELETE + // followed by 2 INSERT into OldCards table. I'm not sure how to fail + // an assertion when an unexpected DML is issued. + + await (t.CommitAsync()); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs index 993e3d5bda..9b9b51b3c1 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace NHibernate.Test.NHSpecificTest.GH3539; - +using System; +using System.Collections.Generic; +using System.Linq; + +namespace NHibernate.Test.NHSpecificTest.GH3539; + public class CardInfo { private readonly ISet _oldCards; @@ -20,17 +20,17 @@ public virtual ISet GetCardsCopy() return _oldCards.ToHashSet(); } - public override bool Equals(object obj) + public override bool Equals(object obj) { - if (obj is null) + if (obj is null) { return false; } - if (ReferenceEquals(this, obj)) + if (ReferenceEquals(this, obj)) { return true; } - if (obj.GetType() != GetType()) + if (obj.GetType() != GetType()) { return false; } @@ -38,10 +38,10 @@ public override bool Equals(object obj) return _oldCards.SetEquals(other._oldCards); } - public override int GetHashCode() + public override int GetHashCode() { var hashCode = new HashCode(); hashCode.Add(_oldCards); return hashCode.ToHashCode(); } -} +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs index ef8bf637d8..59f37127c9 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs @@ -7,21 +7,21 @@ namespace NHibernate.Test.NHSpecificTest.GH3539 { [TestFixture] - public class ImmutableComponentTest : TestCase - { + public class ImmutableComponentTest : TestCase + { protected override string MappingsAssembly { get { return "NHibernate.Test"; } - } - + } + protected override string[] Mappings { get { return Array.Empty(); } - } - + } + protected override void Configure(Configuration configuration) { - using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( + using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( "NHibernate.Test.NHSpecificTest.GH3539.Person.hbm.xml")) { using (StreamReader reader = new StreamReader(stream)) @@ -32,8 +32,8 @@ protected override void Configure(Configuration configuration) configuration.SetProperty(Cfg.Environment.GenerateStatistics, "true"); } } - } - + } + protected override void OnTearDown() { using (ISession s = Sfi.OpenSession()) @@ -41,8 +41,8 @@ protected override void OnTearDown() { s.Delete("from Person"); t.Commit(); - } - + } + base.OnTearDown(); } @@ -61,31 +61,31 @@ public void TestComponent() t.Commit(); s.Flush(); personId = person.Id; - } - + } + using (ISession s = Sfi.OpenSession()) using (ITransaction t = s.BeginTransaction()) - { + { var restored = s.Get(personId); - var oldCardInfo = restored.CardInfo; - - Assert.That(oldCardInfo.GetCardsCopy().Contains("card1")); + var oldCardInfo = restored.CardInfo; + + Assert.That(oldCardInfo.GetCardsCopy().Contains("card1")); Assert.That(oldCardInfo.GetCardsCopy().Contains("card2")); var newCardInfo = new CardInfo("card1", "card2"); Assert.That(oldCardInfo.Equals(newCardInfo), Is.True); - restored.CardInfo = newCardInfo; - - // Expected behaviour: - // + restored.CardInfo = newCardInfo; + + // Expected behaviour: + // // At this point there should be no DML statements because newCardInfo // is the same as the old one. But NHibernate will generate DELETE - // followed by 2 INSERT into OldCards table. I'm not sure how to fail - // an assertion when an unexpected DML is issued. - + // followed by 2 INSERT into OldCards table. I'm not sure how to fail + // an assertion when an unexpected DML is issued. + t.Commit(); } } diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/Person.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/Person.cs index aa3ceee5cb..ce4fe44848 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3539/Person.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/Person.cs @@ -4,8 +4,8 @@ public class Person { private int _id; private int _age; - private CardInfo _cardInfo; - + private CardInfo _cardInfo; + protected Person() { } public Person(int age) @@ -14,19 +14,19 @@ public Person(int age) _age = age; } - public virtual int Id + public virtual int Id { get { return _id; } set { _id = value; } - } - - public virtual int Age + } + + public virtual int Age { get { return _age; } set { _age = value; } } - public virtual CardInfo CardInfo + public virtual CardInfo CardInfo { get { return _cardInfo; } set { _cardInfo = value; } From 6fea5e7abbcabcf877e63648bcde3275bffcffcb Mon Sep 17 00:00:00 2001 From: DmitryMak Date: Thu, 2 May 2024 22:58:55 -0700 Subject: [PATCH 3/7] Update src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs Co-authored-by: Alex Zaytsev --- src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs index 9b9b51b3c1..9596e2b61e 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/CardInfo.cs @@ -41,7 +41,7 @@ public override bool Equals(object obj) public override int GetHashCode() { var hashCode = new HashCode(); - hashCode.Add(_oldCards); + foreach (var card in _oldCards) hashCode.Add(card); return hashCode.ToHashCode(); } } From 3ff5b45a8a8c827fc7bafcc67d1ab8cf9587c619 Mon Sep 17 00:00:00 2001 From: DmitryMak Date: Thu, 2 May 2024 23:00:01 -0700 Subject: [PATCH 4/7] Update src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs Co-authored-by: Alex Zaytsev --- .../NHSpecificTest/GH3539/ImmutableComponentTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs index 59f37127c9..c67bdc4b9e 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs @@ -72,6 +72,7 @@ public void TestComponent() Assert.That(oldCardInfo.GetCardsCopy().Contains("card1")); Assert.That(oldCardInfo.GetCardsCopy().Contains("card2")); + Assert.That(oldCardInfo.GetHashCode(), Is.EqualTo(newCardInfo.GetHashCode())); var newCardInfo = new CardInfo("card1", "card2"); From 0677d5e91a10bdb2fc8da1e1a84e11cce3b31f8b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 3 May 2024 06:02:02 +0000 Subject: [PATCH 5/7] Generate async files --- .../Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs index 05529b5878..6ac282aa4b 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs @@ -83,6 +83,7 @@ public async Task TestComponentAsync() Assert.That(oldCardInfo.GetCardsCopy().Contains("card1")); Assert.That(oldCardInfo.GetCardsCopy().Contains("card2")); + Assert.That(oldCardInfo.GetHashCode(), Is.EqualTo(newCardInfo.GetHashCode())); var newCardInfo = new CardInfo("card1", "card2"); From 1eac99603a875bafaff7ac0979c253ad831a71b9 Mon Sep 17 00:00:00 2001 From: Alex Zaytsev Date: Fri, 3 May 2024 16:06:44 +1000 Subject: [PATCH 6/7] Use standard template --- .../{ImmutableComponentTest.cs => Fixture.cs} | 52 ++++++------------- .../{Person.hbm.xml => Mappings.hbm.xml} | 0 2 files changed, 16 insertions(+), 36 deletions(-) rename src/NHibernate.Test/NHSpecificTest/GH3539/{ImmutableComponentTest.cs => Fixture.cs} (50%) rename src/NHibernate.Test/NHSpecificTest/GH3539/{Person.hbm.xml => Mappings.hbm.xml} (100%) diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs b/src/NHibernate.Test/NHSpecificTest/GH3539/Fixture.cs similarity index 50% rename from src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs rename to src/NHibernate.Test/NHSpecificTest/GH3539/Fixture.cs index c67bdc4b9e..2311b2e50e 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3539/ImmutableComponentTest.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH3539/Fixture.cs @@ -1,43 +1,20 @@ -using System; -using System.IO; -using System.Reflection; using NHibernate.Cfg; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest.GH3539 { [TestFixture] - public class ImmutableComponentTest : TestCase + public class Fixture : BugTestCase { - protected override string MappingsAssembly - { - get { return "NHibernate.Test"; } - } - - protected override string[] Mappings - { - get { return Array.Empty(); } - } - protected override void Configure(Configuration configuration) { - using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( - "NHibernate.Test.NHSpecificTest.GH3539.Person.hbm.xml")) - { - using (StreamReader reader = new StreamReader(stream)) - { - string mapping = reader.ReadToEnd(); - - configuration.AddXml(mapping); - configuration.SetProperty(Cfg.Environment.GenerateStatistics, "true"); - } - } + configuration.SetProperty(Cfg.Environment.GenerateStatistics, "true"); } protected override void OnTearDown() { - using (ISession s = Sfi.OpenSession()) - using (ITransaction t = s.BeginTransaction()) + using (var s = Sfi.OpenSession()) + using (var t = s.BeginTransaction()) { s.Delete("from Person"); t.Commit(); @@ -50,8 +27,8 @@ protected override void OnTearDown() public void TestComponent() { int personId; - using (ISession s = Sfi.OpenSession()) - using (ITransaction t = s.BeginTransaction()) + using (var s = Sfi.OpenSession()) + using (var t = s.BeginTransaction()) { var person = new Person(age: 20) { @@ -63,8 +40,8 @@ public void TestComponent() personId = person.Id; } - using (ISession s = Sfi.OpenSession()) - using (ITransaction t = s.BeginTransaction()) + using (var s = Sfi.OpenSession()) + using (var t = s.BeginTransaction()) { var restored = s.Get(personId); @@ -72,11 +49,11 @@ public void TestComponent() Assert.That(oldCardInfo.GetCardsCopy().Contains("card1")); Assert.That(oldCardInfo.GetCardsCopy().Contains("card2")); - Assert.That(oldCardInfo.GetHashCode(), Is.EqualTo(newCardInfo.GetHashCode())); var newCardInfo = new CardInfo("card1", "card2"); - Assert.That(oldCardInfo.Equals(newCardInfo), Is.True); + Assert.That(oldCardInfo.GetHashCode(), Is.EqualTo(newCardInfo.GetHashCode())); + Assert.That(oldCardInfo.Equals(newCardInfo)); restored.CardInfo = newCardInfo; @@ -84,10 +61,13 @@ public void TestComponent() // // At this point there should be no DML statements because newCardInfo // is the same as the old one. But NHibernate will generate DELETE - // followed by 2 INSERT into OldCards table. I'm not sure how to fail - // an assertion when an unexpected DML is issued. + // followed by 2 INSERT into OldCards table. - t.Commit(); + using (var x = new SqlLogSpy()) + { + t.Commit(); + Assert.That(x.GetWholeLog(), Is.Empty); + } } } } diff --git a/src/NHibernate.Test/NHSpecificTest/GH3539/Person.hbm.xml b/src/NHibernate.Test/NHSpecificTest/GH3539/Mappings.hbm.xml similarity index 100% rename from src/NHibernate.Test/NHSpecificTest/GH3539/Person.hbm.xml rename to src/NHibernate.Test/NHSpecificTest/GH3539/Mappings.hbm.xml From e5648896b53d5f4335afc8e6ab17753d42d30fd0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 3 May 2024 06:08:49 +0000 Subject: [PATCH 7/7] Generate async files --- .../{ImmutableComponentTest.cs => Fixture.cs} | 52 ++++++------------- 1 file changed, 16 insertions(+), 36 deletions(-) rename src/NHibernate.Test/Async/NHSpecificTest/GH3539/{ImmutableComponentTest.cs => Fixture.cs} (58%) diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH3539/Fixture.cs similarity index 58% rename from src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs rename to src/NHibernate.Test/Async/NHSpecificTest/GH3539/Fixture.cs index 6ac282aa4b..342d688f1c 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH3539/ImmutableComponentTest.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH3539/Fixture.cs @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ -using System; -using System.IO; -using System.Reflection; using NHibernate.Cfg; using NUnit.Framework; @@ -18,37 +15,17 @@ namespace NHibernate.Test.NHSpecificTest.GH3539 { using System.Threading.Tasks; [TestFixture] - public class ImmutableComponentTestAsync : TestCase + public class FixtureAsync : BugTestCase { - protected override string MappingsAssembly - { - get { return "NHibernate.Test"; } - } - - protected override string[] Mappings - { - get { return Array.Empty(); } - } - protected override void Configure(Configuration configuration) { - using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( - "NHibernate.Test.NHSpecificTest.GH3539.Person.hbm.xml")) - { - using (StreamReader reader = new StreamReader(stream)) - { - string mapping = reader.ReadToEnd(); - - configuration.AddXml(mapping); - configuration.SetProperty(Cfg.Environment.GenerateStatistics, "true"); - } - } + configuration.SetProperty(Cfg.Environment.GenerateStatistics, "true"); } protected override void OnTearDown() { - using (ISession s = Sfi.OpenSession()) - using (ITransaction t = s.BeginTransaction()) + using (var s = Sfi.OpenSession()) + using (var t = s.BeginTransaction()) { s.Delete("from Person"); t.Commit(); @@ -61,8 +38,8 @@ protected override void OnTearDown() public async Task TestComponentAsync() { int personId; - using (ISession s = Sfi.OpenSession()) - using (ITransaction t = s.BeginTransaction()) + using (var s = Sfi.OpenSession()) + using (var t = s.BeginTransaction()) { var person = new Person(age: 20) { @@ -74,8 +51,8 @@ public async Task TestComponentAsync() personId = person.Id; } - using (ISession s = Sfi.OpenSession()) - using (ITransaction t = s.BeginTransaction()) + using (var s = Sfi.OpenSession()) + using (var t = s.BeginTransaction()) { var restored = await (s.GetAsync(personId)); @@ -83,11 +60,11 @@ public async Task TestComponentAsync() Assert.That(oldCardInfo.GetCardsCopy().Contains("card1")); Assert.That(oldCardInfo.GetCardsCopy().Contains("card2")); - Assert.That(oldCardInfo.GetHashCode(), Is.EqualTo(newCardInfo.GetHashCode())); var newCardInfo = new CardInfo("card1", "card2"); - Assert.That(oldCardInfo.Equals(newCardInfo), Is.True); + Assert.That(oldCardInfo.GetHashCode(), Is.EqualTo(newCardInfo.GetHashCode())); + Assert.That(oldCardInfo.Equals(newCardInfo)); restored.CardInfo = newCardInfo; @@ -95,10 +72,13 @@ public async Task TestComponentAsync() // // At this point there should be no DML statements because newCardInfo // is the same as the old one. But NHibernate will generate DELETE - // followed by 2 INSERT into OldCards table. I'm not sure how to fail - // an assertion when an unexpected DML is issued. + // followed by 2 INSERT into OldCards table. - await (t.CommitAsync()); + using (var x = new SqlLogSpy()) + { + await (t.CommitAsync()); + Assert.That(x.GetWholeLog(), Is.Empty); + } } } }