Skip to content

[5.2] Lazy property with nosetter.pascalcase-underscore accessor #3332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/NHibernate.Test/LazyProperty/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,14 @@ public virtual string ALotOfText
}

public virtual string FieldInterceptor { get; set; }

private byte[] _NoSetterImage;

public virtual byte[] NoSetterImage
{
get { return _NoSetterImage; }
set { _NoSetterImage = value; }
}

}
}
26 changes: 26 additions & 0 deletions src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected override void OnSetUp()
Name = "some name",
Id = 1,
ALotOfText = "a lot of text ...",
NoSetterImage = new byte[10],
FieldInterceptor = "Why not that name?"
});
tx.Commit();
Expand Down Expand Up @@ -210,5 +211,30 @@ public void CanMergeTransientWithLazyProperty()
Assert.That(book.ALotOfText, Is.EqualTo("a lot of text two..."));
}
}

[Test]
public void GetLazyPropertyWithNoSetterAccessor_PropertyShouldBeInitialized()
{
using (ISession s = OpenSession())
{
var book = s.Get<Book>(1);
var image = book.NoSetterImage;
// Fails. Property remains uninitialized after it has been accessed.
Assert.That(NHibernateUtil.IsPropertyInitialized(book, "NoSetterImage"), Is.True);
}
}

[Test]
public void GetLazyPropertyWithNoSetterAccessorTwice_ResultsAreSameObject()
{
using (ISession s = OpenSession())
{
var book = s.Get<Book>(1);
var image = book.NoSetterImage;
var sameImage = book.NoSetterImage;
// Fails. Each call to a property getter returns a new object.
Assert.That(ReferenceEquals(image, sameImage), Is.True);
}
}
}
}
1 change: 1 addition & 0 deletions src/NHibernate.Test/LazyProperty/Mappings.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<property name="Name" />
<property name="ALotOfText" lazy="true" />
<property name="FieldInterceptor" />
<property name="NoSetterImage" access="nosetter.pascalcase-underscore" lazy="true" />
</class>

</hibernate-mapping>