File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ protected override void OnSetUp()
69
69
Id = 1 ,
70
70
ALotOfText = "a lot of text ..." ,
71
71
Image = new byte [ 10 ] ,
72
+ NoSetterImage = new byte [ 10 ] ,
72
73
FieldInterceptor = "Why not that name?"
73
74
} ) ;
74
75
tx . Commit ( ) ;
@@ -393,5 +394,30 @@ public async Task CanMergeTransientWithLazyPropertyInCollectionAsync()
393
394
Assert . That ( book . Words . First ( ) . Content , Is . EqualTo ( new byte [ 1 ] { 0 } ) ) ;
394
395
}
395
396
}
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
+ }
396
422
}
397
423
}
Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ public virtual string ALotOfText
17
17
18
18
public virtual byte [ ] Image { get ; set ; }
19
19
20
+ private byte [ ] _NoSetterImage ;
21
+
22
+ public virtual byte [ ] NoSetterImage
23
+ {
24
+ get { return _NoSetterImage ; }
25
+ set { _NoSetterImage = value ; }
26
+ }
27
+
20
28
public virtual string FieldInterceptor { get ; set ; }
21
29
22
30
public virtual IList < Word > Words { get ; set ; }
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ protected override void OnSetUp()
57
57
Id = 1 ,
58
58
ALotOfText = "a lot of text ..." ,
59
59
Image = new byte [ 10 ] ,
60
+ NoSetterImage = new byte [ 10 ] ,
60
61
FieldInterceptor = "Why not that name?"
61
62
} ) ;
62
63
tx . Commit ( ) ;
@@ -387,5 +388,30 @@ public void CanMergeTransientWithLazyPropertyInCollection()
387
388
Assert . That ( book . Words . First ( ) . Content , Is . EqualTo ( new byte [ 1 ] { 0 } ) ) ;
388
389
}
389
390
}
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
+ }
390
416
}
391
417
}
Original file line number Diff line number Diff line change 11
11
<property name =" Name" />
12
12
<property name =" ALotOfText" lazy =" true" />
13
13
<property name =" Image" lazy =" true" />
14
+ <property name =" NoSetterImage" access =" nosetter.pascalcase-underscore" lazy =" true" />
14
15
<property name =" FieldInterceptor" />
15
16
<bag name =" Words" inverse =" true" generic =" true" cascade =" all-delete-orphan" lazy =" true" >
16
17
<key column =" ParentId" />
You can’t perform that action at this time.
0 commit comments