Skip to content

Lazy property with nosetter.pascalcase-underscore accessor remains uninitialized #3331

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
26 changes: 26 additions & 0 deletions src/NHibernate.Test/Async/LazyProperty/LazyPropertyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected override void OnSetUp()
Id = 1,
ALotOfText = "a lot of text ...",
Image = new byte[10],
NoSetterImage = new byte[10],
FieldInterceptor = "Why not that name?"
});
tx.Commit();
Expand Down Expand Up @@ -391,5 +392,30 @@ public async Task CanMergeTransientWithLazyPropertyInCollectionAsync()
Assert.That(book.Words.First().Content, Is.EqualTo(new byte[1] { 0 }));
}
}

[Test]
public async Task GetLazyPropertyWithNoSetterAccessor_PropertyShouldBeInitializedAsync()
{
using (ISession s = OpenSession())
{
var book = await (s.GetAsync<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 async Task GetLazyPropertyWithNoSetterAccessorTwice_ResultsAreSameObjectAsync()
{
using (ISession s = OpenSession())
{
var book = await (s.GetAsync<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);
}
}
}
}
8 changes: 8 additions & 0 deletions src/NHibernate.Test/LazyProperty/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public virtual string ALotOfText

public virtual byte[] Image { get; set; }

private byte[] _NoSetterImage;

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

public virtual string FieldInterceptor { get; set; }

public virtual IList<Word> Words { get; set; }
Expand Down
26 changes: 26 additions & 0 deletions src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected override void OnSetUp()
Id = 1,
ALotOfText = "a lot of text ...",
Image = new byte[10],
NoSetterImage = new byte[10],
FieldInterceptor = "Why not that name?"
});
tx.Commit();
Expand Down Expand Up @@ -385,5 +386,30 @@ public void CanMergeTransientWithLazyPropertyInCollection()
Assert.That(book.Words.First().Content, Is.EqualTo(new byte[1] { 0 }));
}
}

[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 @@ -11,6 +11,7 @@
<property name="Name" />
<property name="ALotOfText" lazy="true" />
<property name="Image" lazy="true" />
<property name="NoSetterImage" access="nosetter.pascalcase-underscore" lazy="true" />
<property name="FieldInterceptor" />
<bag name="Words" inverse="true" generic="true" cascade="all-delete-orphan" lazy="true" >
<key column="ParentId" />
Expand Down