public void ShouldInitialzeAndCleanupBeforeAndAfterMethodIsCalled() { this.testApplication.CreateObject(typeof(Test), Arg.Is<object[]>(args => (args != null) && (args.Length == 1) && (args[0] == this.initializationManager))).Returns(this.realTest); Test test = new Test(this.initializationManager); test.TestSomething(); Assert.Equal(this.realTest, RemotingServices.GetRealProxy(test).GetType().GetField("target", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(RemotingServices.GetRealProxy(test))); int methodCallId = (int)this.initializationManager.ReceivedCalls().First().GetArguments()[0]; this.initializationManager.Received().Initialize(methodCallId, Arg.Is<TestInitializationContext>(c => (c.Instance == this.realTest) && (c.Method == typeof(Test).GetMethod("TestSomething") && (c.Arguments.Length == 0)))); this.initializationManager.Received().Cleanup(methodCallId, Arg.Is<TestInitializationContext>(c => (c.Instance == this.realTest) && (c.Method == typeof(Test).GetMethod("TestSomething") && (c.Arguments.Length == 0)))); }