private static object Create(MethodBase targetMethod, Type returnType) { dynamic fake = new ExpandoObject(); fake.ReturnsLazily = (Func<dynamic, dynamic>)(f => { MockManager.GetManager(targetMethod).Add(new ReturnValueRule(f(null))); return null; }); fake.Throws = (Func<dynamic, Exception>)(f => { MockManager.GetManager(targetMethod).Add(new ThrowRule(f(null))); return null; }); fake.Invokes = (Func<Delegate, dynamic>)(a => { MockManager.GetManager(targetMethod).Add(new InvokeRule(() => a.FastDynamicInvoke(new object[] { null }))); return null; }); fake.MustHaveHappened = (Action<dynamic>)(a => { Impromptu.InvokeMember(a, "Matches", MockManager.GetManager(targetMethod).Invocations); }); //fake.CallsBaseMethod = Return<IAfterCallSpecifiedConfiguration>.Arguments(() => null); //fake.WhenArgumentsMatch = Return<IReturnValueConfiguration<int>>.Arguments(() => null); targetMethod.Override(i => { var mockManager = MockManager.GetManager(i.InterceptedMethod); return mockManager.Execute(); }); Cop.Intercept(); return Impromptu.DynamicActLike(fake, returnType); }