From: <fab...@us...> - 2010-07-20 19:01:14
|
Revision: 5023 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5023&view=rev Author: fabiomaulo Date: 2010-07-20 19:01:08 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Additional tests with better exception message for NH-2094 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 18:37:34 UTC (rev 5022) +++ trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 19:01:08 UTC (rev 5023) @@ -103,11 +103,11 @@ if (session == null) { - throw new LazyInitializationException("entity with lazy properties is not associated with a session"); + throw new LazyInitializationException(EntityName, null, string.Format("entity with lazy properties is not associated with a session. entity-name:'{0}' property:'{1}'", EntityName, fieldName)); } if (!session.IsOpen || !session.IsConnected) { - throw new LazyInitializationException("session is not connected"); + throw new LazyInitializationException(EntityName, null, string.Format("session is not connected. entity-name:'{0}' property:'{1}'", EntityName, fieldName)); } if (IsUninitializedProperty(fieldName)) Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs 2010-07-20 18:37:34 UTC (rev 5022) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs 2010-07-20 19:01:08 UTC (rev 5023) @@ -1,7 +1,8 @@ using NHibernate.ByteCode.Castle; using NHibernate.Cfg; using NUnit.Framework; - +using SharpTestsEx; + namespace NHibernate.Test.NHSpecificTest.NH2094 { [TestFixture] @@ -50,5 +51,75 @@ } } } + + [Test] + public void WhenAccessNoLazyPropertiesOutsideOfSessionThenNotThrows() + { + try + { + using (var s = OpenSession()) + { + var p = new Person { Id = 1, Name = "Person1", LazyField = "Long field" }; + + s.Save(p); + + s.Flush(); + } + + Person person; + + using (var s = OpenSession()) + { + person = s.Get<Person>(1); + } + string personName; + Executing.This(()=> personName = person.Name).Should().NotThrow(); + } + finally + { + using (var s = OpenSession()) + { + s.Delete("from Person"); + + s.Flush(); + } + } + } + + [Test] + public void WhenAccessLazyPropertiesOutsideOfSessionThenThrows() + { + try + { + using (var s = OpenSession()) + { + var p = new Person { Id = 1, Name = "Person1", LazyField = "Long field" }; + + s.Save(p); + + s.Flush(); + } + + Person person; + + using (var s = OpenSession()) + { + person = s.Get<Person>(1); + } + string lazyField; + var lazyException = Executing.This(() => lazyField = person.LazyField).Should().Throw<LazyInitializationException>().Exception; + lazyException.EntityName.Should().Not.Be.Null(); + lazyException.Message.Should().Contain("LazyField"); + } + finally + { + using (var s = OpenSession()) + { + s.Delete("from Person"); + + s.Flush(); + } + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |