public void OnInvocation() { var expectationScope = new TestExpectationScope(); var invocationInterceptor = new MockInvocationInterceptor(expectationScope); var target = new Target(invocationInterceptor); var invocation = CreateMethodInvocation <IExpectationScope>(target, "Add", new[] { typeof(IExpectation), typeof(bool) }, new object[2]); Assert.Throws <ExpectationsException>(() => invocationInterceptor.OnInvocation(invocation)); expectationScope.CanMeet = true; invocationInterceptor.OnInvocation(invocation); Assert.IsTrue(expectationScope.HasBeenMet); }
public void OnInvocationForObjectMethod() { var baseObject = new BaseObject(); var expectationScope = new TestExpectationScope(); var invocationInterceptor = new MockInvocationInterceptor(expectationScope); var target = new Target(baseObject, invocationInterceptor); var invocation = CreateMethodInvocation <object>(target, "ToString"); int invocationCount = 0; baseObject.ToStringCallback = () => (++invocationCount).ToString(); invocationInterceptor.OnInvocation(invocation); Assert.AreEqual("1", invocation.ReturnValue); Assert.AreEqual(1, invocationCount); }