@@ -250,25 +250,41 @@ public async Task DmlPlansAreCachedAsync()
250
250
251
251
using ( session . BeginTransaction ( ) )
252
252
{
253
+ await ( db . Customers . Where ( c => c . CustomerId == "UNKNOWN" ) . UpdateAsync ( x => new Customer { CompanyName = "Constant1" } ) ) ;
253
254
await ( db . Customers . Where ( c => c . CustomerId == "ALFKI" ) . UpdateAsync ( x => new Customer { CompanyName = x . CompanyName } ) ) ;
254
255
Assert . That (
255
256
cache ,
256
- Has . Count . EqualTo ( 1 ) ,
257
- "First query plan should be cached." ) ;
257
+ Has . Count . EqualTo ( 2 ) ,
258
+ "Query plans should be cached." ) ;
258
259
259
260
using ( var spy = new LogSpy ( queryPlanCacheType ) )
260
261
{
261
- // Should hit plan cache.
262
- await ( db . Customers . Where ( c => c . CustomerId == "ANATR" ) . UpdateAsync ( x => new Customer { CompanyName = x . CompanyName } ) ) ;
263
- Assert . That ( cache , Has . Count . EqualTo ( 1 ) , "Second query should not cause a plan to be cached." ) ;
262
+ //Queries below should hit plan cache.
263
+ using ( var sqlSpy = new SqlLogSpy ( ) )
264
+ {
265
+ await ( db . Customers . Where ( c => c . CustomerId == "ANATR" ) . UpdateAsync ( x => new Customer { CompanyName = x . CompanyName } ) ) ;
266
+ await ( db . Customers . Where ( c => c . CustomerId == "UNKNOWN" ) . UpdateAsync ( x => new Customer { CompanyName = "Constant2" } ) ) ;
267
+
268
+ var sqlEvents = sqlSpy . Appender . GetEvents ( ) ;
269
+ Assert . That (
270
+ sqlEvents [ 0 ] . RenderedMessage ,
271
+ Does . Contain ( "ANATR" ) . And . Not . Contain ( "UNKNOWN" ) . And . Not . Contain ( "Constant1" ) ,
272
+ "Unexpected constant parameter value" ) ;
273
+ Assert . That (
274
+ sqlEvents [ 1 ] . RenderedMessage ,
275
+ Does . Contain ( "UNKNOWN" ) . And . Contain ( "Constant2" ) . And . Not . Contain ( "Constant1" ) ,
276
+ "Unexpected constant parameter value" ) ;
277
+ }
278
+
279
+ Assert . That ( cache , Has . Count . EqualTo ( 2 ) , "Additional queries should not cause a plan to be cached." ) ;
264
280
Assert . That (
265
281
spy . GetWholeLog ( ) ,
266
282
Does
267
283
. Contain ( "located HQL query plan in cache" )
268
284
. And . Not . Contain ( "unable to locate HQL query plan in cache" ) ) ;
269
285
270
286
await ( db . Customers . Where ( c => c . CustomerId == "ANATR" ) . UpdateAsync ( x => new Customer { ContactName = x . ContactName } ) ) ;
271
- Assert . That ( cache , Has . Count . EqualTo ( 2 ) , "Third query should be cached" ) ;
287
+ Assert . That ( cache , Has . Count . EqualTo ( 3 ) , "Query should be cached" ) ;
272
288
}
273
289
}
274
290
}
0 commit comments