Skip to content

Commit 4dd592a

Browse files
sashakboobahusoid
authored andcommitted
test for issue with nosetter.pascalcase-underscore
1 parent 8067451 commit 4dd592a

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

src/NHibernate.Test/Async/LazyProperty/LazyPropertyFixture.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected override void OnSetUp()
6969
Id = 1,
7070
ALotOfText = "a lot of text ...",
7171
Image = new byte[10],
72+
NoSetterImage = new byte[10],
7273
FieldInterceptor = "Why not that name?"
7374
});
7475
tx.Commit();
@@ -393,5 +394,30 @@ public async Task CanMergeTransientWithLazyPropertyInCollectionAsync()
393394
Assert.That(book.Words.First().Content, Is.EqualTo(new byte[1] { 0 }));
394395
}
395396
}
397+
398+
[Test]
399+
public async Task GetLazyPropertyWithNoSetterAccessor_PropertyShouldBeInitializedAsync()
400+
{
401+
using (ISession s = OpenSession())
402+
{
403+
var book = await (s.GetAsync<Book>(1));
404+
var image = book.NoSetterImage;
405+
// Fails. Property remains uninitialized after it has been accessed.
406+
Assert.That(NHibernateUtil.IsPropertyInitialized(book, "NoSetterImage"), Is.True);
407+
}
408+
}
409+
410+
[Test]
411+
public async Task GetLazyPropertyWithNoSetterAccessorTwice_ResultsAreSameObjectAsync()
412+
{
413+
using (ISession s = OpenSession())
414+
{
415+
var book = await (s.GetAsync<Book>(1));
416+
var image = book.NoSetterImage;
417+
var sameImage = book.NoSetterImage;
418+
// Fails. Each call to a property getter returns a new object.
419+
Assert.That(ReferenceEquals(image, sameImage), Is.True);
420+
}
421+
}
396422
}
397423
}

src/NHibernate.Test/LazyProperty/Book.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public virtual string ALotOfText
1717

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

20+
private byte[] _NoSetterImage;
21+
22+
public virtual byte[] NoSetterImage
23+
{
24+
get { return _NoSetterImage; }
25+
set { _NoSetterImage = value; }
26+
}
27+
2028
public virtual string FieldInterceptor { get; set; }
2129

2230
public virtual IList<Word> Words { get; set; }

src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected override void OnSetUp()
5757
Id = 1,
5858
ALotOfText = "a lot of text ...",
5959
Image = new byte[10],
60+
NoSetterImage = new byte[10],
6061
FieldInterceptor = "Why not that name?"
6162
});
6263
tx.Commit();
@@ -387,5 +388,30 @@ public void CanMergeTransientWithLazyPropertyInCollection()
387388
Assert.That(book.Words.First().Content, Is.EqualTo(new byte[1] { 0 }));
388389
}
389390
}
391+
392+
[Test]
393+
public void GetLazyPropertyWithNoSetterAccessor_PropertyShouldBeInitialized()
394+
{
395+
using (ISession s = OpenSession())
396+
{
397+
var book = s.Get<Book>(1);
398+
var image = book.NoSetterImage;
399+
// Fails. Property remains uninitialized after it has been accessed.
400+
Assert.That(NHibernateUtil.IsPropertyInitialized(book, "NoSetterImage"), Is.True);
401+
}
402+
}
403+
404+
[Test]
405+
public void GetLazyPropertyWithNoSetterAccessorTwice_ResultsAreSameObject()
406+
{
407+
using (ISession s = OpenSession())
408+
{
409+
var book = s.Get<Book>(1);
410+
var image = book.NoSetterImage;
411+
var sameImage = book.NoSetterImage;
412+
// Fails. Each call to a property getter returns a new object.
413+
Assert.That(ReferenceEquals(image, sameImage), Is.True);
414+
}
415+
}
390416
}
391417
}

src/NHibernate.Test/LazyProperty/Mappings.hbm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<property name="Name" />
1212
<property name="ALotOfText" lazy="true" />
1313
<property name="Image" lazy="true" />
14+
<property name="NoSetterImage" access="nosetter.pascalcase-underscore" lazy="true" />
1415
<property name="FieldInterceptor" />
1516
<bag name="Words" inverse="true" generic="true" cascade="all-delete-orphan" lazy="true" >
1617
<key column="ParentId" />

0 commit comments

Comments
 (0)