public void TestProfilingSession_getCurrent_FromHttpContext()
        {
            var mockProfiler = new Mock<IProfiler>();
            var expected = new ProfilingSession(mockProfiler.Object);
            var mockHttpContext = new HttpContextMock();
            mockHttpContext.Object.Items["nano_profiler::current_profiling_session"] = expected;
            HttpContext.Current = mockHttpContext.Object;

            Assert.AreEqual(expected, ProfilingSession.Current);
        }
        public void TestProfilingSession_Start()
        {
            // mock http context
            var mockHttpContext = new HttpContextMock();
            HttpContext.Current = mockHttpContext.Object;

            // ensure HttpContextCallContextProfilingSessionContainer is in use
            Assert.IsTrue(ProfilingSession.ProfilingSessionContainer is WebProfilingSessionContainer);

            // mock profiler and provider
            var profilerId = Guid.NewGuid();
            var mockProfiler = new Mock<IProfiler>();
            mockProfiler.Setup(p => p.Id).Returns(profilerId);
            var mockProfilerProvider = new Mock<IProfilerProvider>();
            mockProfilerProvider.Setup(provider => provider.Start(It.IsAny<string>(), It.IsAny<IProfilingStorage>(), It.IsAny<string[]>())).Returns(mockProfiler.Object);
            ProfilingSession.ProfilerProvider = mockProfilerProvider.Object;
            Assert.AreEqual(mockProfilerProvider.Object, ProfilingSession.ProfilerProvider);

            // mock profiling storage
            var mockProfilingStorage = new Mock<IProfilingStorage>();
            ProfilingSession.ProfilingStorage = mockProfilingStorage.Object;
            Assert.AreEqual(mockProfilingStorage.Object, ProfilingSession.ProfilingStorage);

            // execute
            ProfilingSession.Start("test");

            Assert.AreEqual(mockProfiler.Object, ProfilingSession.Current.Profiler);
            Assert.AreEqual(mockProfiler.Object, (mockHttpContext.Object.Items["nano_profiler::current_profiling_session"] as ProfilingSession).Profiler);
            Assert.AreEqual(mockProfiler.Object.Id, CallContext.LogicalGetData("nano_profiler::current_profiling_session_id"));
        }