@@ -292,6 +292,39 @@ public async Task TrackingOptionsAsync(bool track)
292
292
CheckConnectionTracking ( track , profiler , cmdString , true ) ;
293
293
}
294
294
295
+ [ Fact ]
296
+ public void ShimProfiler ( )
297
+ {
298
+ var options = new MiniProfilerTestOptions { } ;
299
+ var profiler = options . StartProfiler ( "Shimming" ) ;
300
+ var currentDbProfiler = new CurrentDbProfiler ( ( ) => profiler ) ;
301
+
302
+ const string cmdString = "Select 1" ;
303
+ GetUnopenedConnection ( currentDbProfiler ) . Query ( cmdString ) ;
304
+
305
+ CheckConnectionTracking ( false , profiler , cmdString , false ) ;
306
+ }
307
+
308
+ private class CurrentDbProfiler : IDbProfiler
309
+ {
310
+ private Func < IDbProfiler > GetProfiler { get ; }
311
+ public CurrentDbProfiler ( Func < IDbProfiler > getProfiler ) => GetProfiler = getProfiler ;
312
+
313
+ public bool IsActive => ( ( IDbProfiler ) MiniProfiler . Current ) ? . IsActive ?? false ;
314
+
315
+ public void ExecuteFinish ( IDbCommand profiledDbCommand , SqlExecuteType executeType , DbDataReader reader ) =>
316
+ GetProfiler ( ) ? . ExecuteFinish ( profiledDbCommand , executeType , reader ) ;
317
+
318
+ public void ExecuteStart ( IDbCommand profiledDbCommand , SqlExecuteType executeType ) =>
319
+ GetProfiler ( ) ? . ExecuteStart ( profiledDbCommand , executeType ) ;
320
+
321
+ public void OnError ( IDbCommand profiledDbCommand , SqlExecuteType executeType , Exception exception ) =>
322
+ GetProfiler ( ) ? . OnError ( profiledDbCommand , executeType , exception ) ;
323
+
324
+ public void ReaderFinish ( IDataReader reader ) =>
325
+ GetProfiler ( ) ? . ReaderFinish ( reader ) ;
326
+ }
327
+
295
328
private void CheckConnectionTracking ( bool track , MiniProfiler profiler , string command , bool async )
296
329
{
297
330
Assert . NotNull ( profiler . Root . CustomTimings ) ;
@@ -312,7 +345,7 @@ private void CheckConnectionTracking(bool track, MiniProfiler profiler, string c
312
345
}
313
346
}
314
347
315
- private ProfiledDbConnection GetUnopenedConnection ( MiniProfiler profiler ) => new ProfiledDbConnection ( Fixture . GetConnection ( ) , profiler ) ;
348
+ private ProfiledDbConnection GetUnopenedConnection ( IDbProfiler profiler ) => new ProfiledDbConnection ( Fixture . GetConnection ( ) , profiler ) ;
316
349
317
350
private CountingConnection GetConnection ( )
318
351
{
0 commit comments