8
8
9
9
namespace NHibernate . Test . NHSpecificTest . GH3176
10
10
{
11
- [ TestFixture ]
11
+ [ TestFixture ( CacheFactory . ReadOnly ) ]
12
+ [ TestFixture ( CacheFactory . NonstrictReadWrite ) ]
13
+ [ TestFixture ( CacheFactory . ReadWrite ) ]
12
14
public class ByCodeFixture : TestCaseMappingByCode
13
15
{
16
+ public ByCodeFixture ( string cacheStrategy )
17
+ {
18
+ CacheConcurrencyStrategy = cacheStrategy ;
19
+ }
20
+
21
+ protected override string CacheConcurrencyStrategy { get ; }
22
+
23
+ private int _id ;
24
+
14
25
protected override HbmMapping GetMappings ( )
15
26
{
16
27
var mapper = new ModelMapper ( ) ;
@@ -26,7 +37,6 @@ protected override HbmMapping GetMappings()
26
37
m . Property ( x => x . Field ) ;
27
38
m . Lazy ( true ) ;
28
39
} ) ;
29
- rc . Cache ( x => x . Usage ( CacheUsage . ReadWrite ) ) ;
30
40
} ) ;
31
41
32
42
return mapper . CompileMappingForAllExplicitlyAddedEntities ( ) ;
@@ -47,6 +57,7 @@ protected override void OnSetUp()
47
57
{
48
58
var e1 = new Entity { Name = "Bob" , Component = new Component ( ) { Field = "Jim" } } ;
49
59
session . Save ( e1 ) ;
60
+ _id = e1 . Id ;
50
61
51
62
var e2 = new Entity { Name = "Sally" } ;
52
63
session . Save ( e2 ) ;
@@ -96,6 +107,32 @@ public void TestPreLoadedData()
96
107
}
97
108
}
98
109
110
+ [ Test ]
111
+ public void InitializedLazyPropertyShouldBeCached ( )
112
+ {
113
+ using ( var session = OpenSession ( ) )
114
+ using ( var transaction = session . BeginTransaction ( ) )
115
+ {
116
+ var e = session . Get < Entity > ( _id ) ;
117
+ Assert . That ( e . Component ? . Field , Is . EqualTo ( "Jim" ) ) ;
118
+
119
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( e , "Component" ) , Is . True ) ;
120
+ transaction . Commit ( ) ;
121
+ }
122
+
123
+ using ( var session = OpenSession ( ) )
124
+ using ( var transaction = session . BeginTransaction ( ) )
125
+ {
126
+ var e = session . Get < Entity > ( _id ) ;
127
+
128
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( e , "Component" ) , Is . True , "Lazy property is not cached" ) ;
129
+ var field = e . Component ? . Field ;
130
+
131
+ Assert . That ( field , Is . EqualTo ( "Jim" ) ) ;
132
+ transaction . Commit ( ) ;
133
+ }
134
+ }
135
+
99
136
[ Test ]
100
137
public void TestNonPreLoadedData ( )
101
138
{
0 commit comments