コード例 #1
0
        public async Task TrackingOptionsAsync(bool track)
        {
            var options = new MiniProfilerTestOptions { TrackConnectionOpenClose = track };
            var profiler = options.StartProfiler("Tracking: " + track);

            const string cmdString = "Select 1";
            await GetUnopenedConnection(profiler).QueryAsync(cmdString).ConfigureAwait(false);

            CheckConnectionTracking(track, profiler, cmdString, true, true);
        }
コード例 #2
0
        public void TrackingOptions(bool track)
        {
            var options = new MiniProfilerTestOptions { TrackConnectionOpenClose = track };
            var profiler = options.StartProfiler("Tracking: " + track);

            const string cmdString = "Select 1";
            GetUnopenedConnection(profiler).Query(cmdString);

            CheckConnectionTracking(track, profiler, cmdString, false, false);
        }
コード例 #3
0
        public void ShimProfiler()
        {
            var options = new MiniProfilerTestOptions();
            var profiler = options.StartProfiler("Shimming");
            var currentDbProfiler = new CurrentDbProfiler(() => MiniProfiler.Current);

            const string cmdString = "Select 1";
            GetUnopenedConnection(currentDbProfiler).Query(cmdString);

            CheckConnectionTracking(false, profiler, cmdString, false, false);
        }
コード例 #4
0
        public void AlwaysWrapReaders()
        {
            var options           = new MiniProfilerTestOptions();
            var profiler          = options.StartProfiler(nameof(AlwaysWrapReaders));
            var currentDbProfiler = new CurrentDbProfiler(() => MiniProfiler.Current);

            const string cmdString = "Select 1";

            // Profiler is active
            using (var conn = new OverrideTestConnection(Fixture.GetConnection(), currentDbProfiler))
            {
                // Always wrap when active, regardless of setting
                using (var reader = conn.ExecuteReader(cmdString))
                {
                    Assert.True(reader is IWrappedDataReader wrappedReader && wrappedReader.Reader is ProfiledDbDataReader);
                }
                conn.AlwaysWrapReaders = true;
                using (var reader = conn.ExecuteReader(cmdString))
                {
                    Assert.True(reader is IWrappedDataReader wrappedReader && wrappedReader.Reader is ProfiledDbDataReader);
                }
            }

            // Profile is inactive
            profiler.Stop();
            using (var conn = new OverrideTestConnection(Fixture.GetConnection(), currentDbProfiler))
            {
                // Should not wrap by default here
                using (var reader = conn.ExecuteReader(cmdString))
                {
                    Assert.False(reader is IWrappedDataReader wrappedReader && wrappedReader.Reader is ProfiledDbDataReader);
                }
                conn.AlwaysWrapReaders = true;
                using (var reader = conn.ExecuteReader(cmdString))
                {
                    Assert.True(reader is IWrappedDataReader wrappedReader && wrappedReader.Reader is ProfiledDbDataReader);
                }
            }
        }