public void TestDeepProfilingInterceptionBehavior() { 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; ProfilingSession.Start("test"); var stepCalled = false; mockProfiler.Setup(p => p.Step(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<string>())).Callback<string, IEnumerable<string>, string>((name, tags, executeType) => { stepCalled = true; }); var testObj = new TestClass(); var method1 = typeof(TestClass).GetMethod("Method1"); var mockFilter = new Mock<IDeepProfilingFilter>(); mockFilter.Setup(f => f.ShouldBeProfiled(typeof(TestClass))).Returns(true); var target = new DeepProfilingInterceptionBehavior() as IInterceptionBehavior; Assert.AreEqual(Type.EmptyTypes, target.GetRequiredInterfaces()); Assert.IsTrue(target.WillExecute); var mockInput1 = new Mock<IMethodInvocation>(); mockInput1.Setup(i => i.MethodBase).Returns(method1); mockInput1.Setup(i => i.Target).Returns(testObj); target.Invoke(mockInput1.Object, () => ((input, next) => { testObj.Method1(); return null; })); Assert.IsTrue(stepCalled); Assert.IsTrue(testObj.Method1Invoked); }