@@ -186,6 +186,55 @@ public async Task ModifiableSessionReadOnlyCriteriaAsync()
186
186
}
187
187
}
188
188
189
+ [ Test ]
190
+ public async Task ModifiableSessionReadOnlyClonedCriteriaAsync ( )
191
+ {
192
+ await ( DefaultTestSetupAsync ( ) ) ;
193
+
194
+ using ( ISession s = OpenSession ( ) )
195
+ using ( ITransaction t = s . BeginTransaction ( ) )
196
+ {
197
+ ICriteria criteria = ( ICriteria ) s . CreateCriteria < Student > ( ) . SetReadOnly ( true ) . Clone ( ) ;
198
+ Assert . That ( s . DefaultReadOnly , Is . False ) ;
199
+ Assert . That ( criteria . IsReadOnlyInitialized , Is . True , "Cloned criteria must have IsReadOnlyInitialized == true" ) ;
200
+ Assert . That ( criteria . IsReadOnly , Is . True , "Cloned criteria must be readonly" ) ;
201
+
202
+ Student gavin = await ( criteria . UniqueResultAsync < Student > ( ) ) ;
203
+ Assert . That ( s . DefaultReadOnly , Is . False ) ;
204
+ Assert . That ( criteria . IsReadOnlyInitialized , Is . True ) ;
205
+ Assert . That ( criteria . IsReadOnly , Is . True ) ;
206
+ Assert . That ( s . IsReadOnly ( gavin ) , Is . True ) ;
207
+ Assert . That ( NHibernateUtil . IsInitialized ( gavin . PreferredCourse ) , Is . False ) ;
208
+ await ( CheckProxyReadOnlyAsync ( s , gavin . PreferredCourse , true ) ) ;
209
+ Assert . That ( NHibernateUtil . IsInitialized ( gavin . PreferredCourse ) , Is . False ) ;
210
+
211
+ await ( NHibernateUtil . InitializeAsync ( gavin . PreferredCourse ) ) ;
212
+ Assert . That ( NHibernateUtil . IsInitialized ( gavin . PreferredCourse ) , Is . True ) ;
213
+ await ( CheckProxyReadOnlyAsync ( s , gavin . PreferredCourse , true ) ) ;
214
+ Assert . That ( NHibernateUtil . IsInitialized ( gavin . Enrolments ) , Is . False ) ;
215
+
216
+ await ( NHibernateUtil . InitializeAsync ( gavin . Enrolments ) ) ;
217
+ Assert . That ( NHibernateUtil . IsInitialized ( gavin . Enrolments ) , Is . True ) ;
218
+ Assert . That ( gavin . Enrolments . Count , Is . EqualTo ( 1 ) ) ;
219
+ IEnumerator < Enrolment > enrolments = gavin . Enrolments . GetEnumerator ( ) ;
220
+ enrolments . MoveNext ( ) ;
221
+ Enrolment enrolment = enrolments . Current ;
222
+ Assert . That ( s . IsReadOnly ( enrolment ) , Is . False ) ;
223
+ Assert . That ( NHibernateUtil . IsInitialized ( enrolment . Course ) , Is . False ) ;
224
+ await ( CheckProxyReadOnlyAsync ( s , enrolment . Course , false ) ) ;
225
+
226
+ await ( NHibernateUtil . InitializeAsync ( enrolment . Course ) ) ;
227
+ await ( CheckProxyReadOnlyAsync ( s , enrolment . Course , false ) ) ;
228
+
229
+ await ( s . DeleteAsync ( gavin . PreferredCourse ) ) ;
230
+ await ( s . DeleteAsync ( gavin ) ) ;
231
+ await ( s . DeleteAsync ( enrolment . Course ) ) ;
232
+ await ( s . DeleteAsync ( enrolment ) ) ;
233
+
234
+ await ( t . CommitAsync ( ) ) ;
235
+ }
236
+ }
237
+
189
238
[ Test ]
190
239
public async Task ModifiableSessionModifiableCriteriaAsync ( )
191
240
{
0 commit comments