Esempio n. 1
0
        public void TestDbProfiler()
        {
            var mockStorage = new Mock<IProfilingStorage>();
            var profiler = new Profiler("test", mockStorage.Object, null);
            var target = new DbProfiler(profiler) as IDbProfiler;

            var stepId = Guid.NewGuid();
            ProfilingSession.ProfilingSessionContainer.CurrentSessionStepId = stepId;
            var executeCalled = false;
            var mockCommand = new Mock<IDbCommand>();
            mockCommand.Setup(cmd => cmd.CommandText).Returns("test");
            var mockReader = new Mock<IDataReader>();

            // test execute reader
            target.ExecuteDbCommand(DbExecuteType.Reader, mockCommand.Object, () =>
            {
                executeCalled = true;
                return mockReader.Object;
            }, new[] { "tag1" });
            Assert.IsTrue(executeCalled);
            Assert.AreEqual(0, (profiler as IProfiler).CustomTimings.Count());
            target.DataReaderFinished(new ProfiledDbDataReader(mockReader.Object, target));
            Assert.AreEqual(1, (profiler as IProfiler).CustomTimings.Count());
            Assert.AreEqual("TAG1", (profiler as IProfiler).CustomTimings.Last().Tags.First());

            // test execute nonquery
            executeCalled = false;
            target.ExecuteDbCommand(DbExecuteType.NonQuery, mockCommand.Object, () =>
            {
                executeCalled = true;
                return null;
            }, null);
            Assert.IsTrue(executeCalled);
            Assert.AreEqual(2, (profiler as IProfiler).CustomTimings.Count());

            // test DataReaderFinished with invalid reader, it should not throw exception
            target.DataReaderFinished(null);
        }
Esempio n. 2
0
        public void TestDbProfiler_ExecuteDbCommand_InvalidCommand()
        {
            var mockStorage = new Mock<IProfilingStorage>();
            var profiler = new Profiler("test", mockStorage.Object, null);
            var target = new DbProfiler(profiler) as IDbProfiler;

            var executeCalled = false;
            target.ExecuteDbCommand(DbExecuteType.Reader, null, () =>
            {
                executeCalled = true;
                return null;
            }, null);

            Assert.IsTrue(executeCalled);
        }
Esempio n. 3
0
        public void TestDbProfiler_ExecuteDbCommand_InvalidExecute()
        {
            var mockStorage = new Mock<IProfilingStorage>();
            var profiler = new Profiler("test", mockStorage.Object, null);
            var mockCommand = new Mock<IDbCommand>();
            var target = new DbProfiler(profiler) as IDbProfiler;

            // execute empty execute should not throw exception
            target.ExecuteDbCommand(DbExecuteType.Reader, mockCommand.Object, null, null);
        }