From cf007bdc8d893b04e569b52911d9f0c53cdcc7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= Date: Wed, 28 Mar 2018 20:26:17 +0200 Subject: [PATCH 1/2] Remove class baseType interfaces from proxified methods Revert the lazy property proxy to its 5.0.x behavior. This allows to avoid proxifying explicitly implemented interface methods, which are currently not supported by the dynamix proxy (lazy properties proxy). Add test case adapted from gcesena test case. Fixes #1628 Co-authored-by: gcesena <37696182+gcesena@users.noreply.github.com> --- .../Async/NHSpecificTest/GH1628/Fixture.cs | 72 +++++++++++++++++++ .../NHSpecificTest/GH1628/Entity.cs | 16 +++++ .../NHSpecificTest/GH1628/Fixture.cs | 61 ++++++++++++++++ .../NHSpecificTest/GH1628/Mappings.hbm.xml | 11 +++ .../Proxy/DynamicProxy/ProxyFactory.cs | 2 +- 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH1628/Entity.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs new file mode 100644 index 00000000000..ef450f63ff6 --- /dev/null +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by AsyncGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH1628 +{ + using System.Threading.Tasks; + [TestFixture] + public class FixtureAsync : BugTestCase + { + protected override void OnSetUp() + { + using (var session = OpenSession()) + using (var transaction = session.BeginTransaction()) + { + var e1 = new Entity + { + Id = 1, + Name = "Bob", + ALongText = "Bob's very long text" + }; + session.Save(e1); + + var e2 = new Entity + { + Id = 2, + Name = "Sally", + ALongText = "Sally's very long text" + }; + 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 NHbernate ordering the deletes, but this will cause + // loading the entities in the session. + session.CreateQuery("delete from System.Object").ExecuteUpdate(); + + transaction.Commit(); + } + } + + [Test] + public async Task ShouldNotThrowStackOverflowExceptionAsync() + { + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + IEntity result = await (session.GetAsync(2)); + + Assert.That(result.Thing, Is.EqualTo(null)); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH1628/Entity.cs b/src/NHibernate.Test/NHSpecificTest/GH1628/Entity.cs new file mode 100644 index 00000000000..8dc238e8daa --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH1628/Entity.cs @@ -0,0 +1,16 @@ +namespace NHibernate.Test.NHSpecificTest.GH1628 +{ +public interface IEntity +{ + object Thing { get; } +} + +public class Entity : IEntity +{ + public virtual int Id { get; set; } + + object IEntity.Thing { get { return null; } } + public virtual string Name { get; set; } + public virtual string ALongText { get; set; } +} +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs new file mode 100644 index 00000000000..4d4f6673dfa --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs @@ -0,0 +1,61 @@ +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH1628 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnSetUp() + { + using (var session = OpenSession()) + using (var transaction = session.BeginTransaction()) + { + var e1 = new Entity + { + Id = 1, + Name = "Bob", + ALongText = "Bob's very long text" + }; + session.Save(e1); + + var e2 = new Entity + { + Id = 2, + Name = "Sally", + ALongText = "Sally's very long text" + }; + 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 NHbernate 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 ShouldNotThrowStackOverflowException() + { + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + IEntity result = session.Get(2); + + Assert.That(result.Thing, Is.EqualTo(null)); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml new file mode 100644 index 00000000000..5bb88d3c677 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs b/src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs index 1865190f182..4df3f5bf588 100644 --- a/src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs +++ b/src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs @@ -98,8 +98,8 @@ private TypeInfo CreateUncachedProxyType(System.Type baseType, IReadOnlyCollecti { parentType = typeof (ProxyDummy); interfaces.Add(baseType); + interfaces.UnionWith(baseType.GetInterfaces()); } - interfaces.UnionWith(baseType.GetInterfaces()); // Add the ISerializable interface so that it can be implemented interfaces.Add(typeof (ISerializable)); From c13ff7182ad82b566eca54a1a3f2439594813c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= Date: Fri, 30 Mar 2018 12:41:32 +0200 Subject: [PATCH 2/2] Fix GH1628 test To be squashed --- src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs | 4 ++-- src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs | 4 ++-- src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs index ef450f63ff6..147257ed1cb 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH1628/Fixture.cs @@ -64,8 +64,8 @@ public async Task ShouldNotThrowStackOverflowExceptionAsync() using (session.BeginTransaction()) { IEntity result = await (session.GetAsync(2)); - - Assert.That(result.Thing, Is.EqualTo(null)); + Assert.That(result, Is.Not.Null); + Assert.That(result.Thing, Is.Null); } } } diff --git a/src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs index 4d4f6673dfa..34ace2d9653 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH1628/Fixture.cs @@ -53,8 +53,8 @@ public void ShouldNotThrowStackOverflowException() using (session.BeginTransaction()) { IEntity result = session.Get(2); - - Assert.That(result.Thing, Is.EqualTo(null)); + Assert.That(result, Is.Not.Null); + Assert.That(result.Thing, Is.Null); } } } diff --git a/src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml index 5bb88d3c677..eee10a244f0 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml +++ b/src/NHibernate.Test/NHSpecificTest/GH1628/Mappings.hbm.xml @@ -3,7 +3,7 @@ namespace="NHibernate.Test.NHSpecificTest.GH1628"> - +