@@ -65,6 +65,79 @@ protected override void OnTearDown()
65
65
Assert . AreEqual ( 0 , statistics . SecondLevelCacheMissCount , "Second level cache miss count" ) ;
66
66
}
67
67
68
+ private void OneToOneUpdateTest < TPerson , TDetails > ( ) where TPerson : Person , new ( ) where TDetails : Details , new ( )
69
+ {
70
+ List < object > ids = this . CreatePersonAndDetails < TPerson , TDetails > ( ) ;
71
+
72
+ IStatistics statistics = Sfi . Statistics ;
73
+
74
+ // Clear the second level cache and the statistics
75
+ Sfi . EvictEntity ( typeof ( TPerson ) . FullName ) ;
76
+ Sfi . EvictEntity ( typeof ( TDetails ) . FullName ) ;
77
+ Sfi . EvictQueries ( ) ;
78
+
79
+ statistics . Clear ( ) ;
80
+
81
+ // Fill the empty caches with data.
82
+ this . FetchPeopleById < TPerson > ( ids ) ;
83
+
84
+ // Verify that no data was retrieved from the cache.
85
+ Assert . AreEqual ( 0 , statistics . SecondLevelCacheHitCount , "Second level cache hit count" ) ;
86
+ statistics . Clear ( ) ;
87
+
88
+ int personId = DeleteDetailsFromFirstPerson < TPerson > ( ) ;
89
+
90
+ // Verify that the cache was updated
91
+ Assert . AreEqual ( 1 , statistics . SecondLevelCachePutCount , "Second level cache put count" ) ;
92
+ statistics . Clear ( ) ;
93
+
94
+ // Verify that the Person was updated in the cache
95
+ using ( ISession s = Sfi . OpenSession ( ) )
96
+ using ( ITransaction tx = s . BeginTransaction ( ) )
97
+ {
98
+ TPerson person = s . Get < TPerson > ( personId ) ;
99
+
100
+ Assert . IsNull ( person . Details ) ;
101
+ }
102
+
103
+ Assert . AreEqual ( 0 , statistics . SecondLevelCacheMissCount , "Second level cache miss count" ) ;
104
+ statistics . Clear ( ) ;
105
+
106
+ // Verify that the Details was removed from the cache and deleted.
107
+ using ( ISession s = Sfi . OpenSession ( ) )
108
+ using ( ITransaction tx = s . BeginTransaction ( ) )
109
+ {
110
+ TDetails details = s . Get < TDetails > ( personId ) ;
111
+
112
+ Assert . Null ( details ) ;
113
+ }
114
+
115
+ Assert . AreEqual ( 0 , statistics . SecondLevelCacheHitCount , "Second level cache hit count" ) ;
116
+ }
117
+
118
+ private int DeleteDetailsFromFirstPerson < TPerson > ( ) where TPerson : Person
119
+ {
120
+ using ( ISession s = Sfi . OpenSession ( ) )
121
+ using ( ITransaction tx = s . BeginTransaction ( ) )
122
+ {
123
+ // Get the first person with details.
124
+ Person person = s . QueryOver < TPerson > ( )
125
+ . Where ( p => p . Details != null )
126
+ . Take ( 1 )
127
+ . SingleOrDefault ( ) ;
128
+
129
+ Assert . NotNull ( person ) ;
130
+ Assert . NotNull ( person . Details ) ;
131
+
132
+ s . SaveOrUpdate ( person ) ;
133
+ person . Details = null ;
134
+
135
+ tx . Commit ( ) ;
136
+
137
+ return person . Id ;
138
+ }
139
+ }
140
+
68
141
private List < object > CreatePersonAndDetails < TPerson , TDetails > ( ) where TPerson : Person , new ( ) where TDetails : Details , new ( )
69
142
{
70
143
List < object > ids = new List < object > ( ) ;
@@ -125,5 +198,17 @@ public void OneToOneCacheFetchByRef()
125
198
{
126
199
OneToOneFetchTest < PersonByRef , DetailsByRef > ( ) ;
127
200
}
201
+
202
+ [ Test ]
203
+ public void OneToOneCacheUpdateByForeignKey ( )
204
+ {
205
+ OneToOneUpdateTest < PersonByFK , DetailsByFK > ( ) ;
206
+ }
207
+
208
+ [ Test ]
209
+ public void OneToOneCacheUpdateByRef ( )
210
+ {
211
+ OneToOneUpdateTest < PersonByRef , DetailsByRef > ( ) ;
212
+ }
128
213
}
129
214
}
0 commit comments