public void Invoke(Invocation invocation) { if (invocation.Method.DeclaringType == typeof (object)) { if (invocation.Method.Equals(EqualsMethod)) { invocation.Result = ReferenceEquals(invocation.Receiver, invocation.Parameters[0]); } else { invocation.InvokeOn(identityProvider); } } else { next.Invoke(invocation); } }
public void TrapsExceptionsWhenInvokedOnAnotherObject() { var exception = new Exception("thrown from Foo"); invocation = new Invocation(receiver, FOO_METHOD, new object[] {"input", null}); var mockFoo = new MockFoo(); mockFoo.Foo_ExpectedInput = "input"; mockFoo.Foo_Exception = exception; invocation.InvokeOn(mockFoo); Assert.IsTrue(mockFoo.FooWasInvoked, "Foo should have been invoked"); Assert.AreSame(exception, invocation.Exception, "exception"); }
/// <summary> /// Executes the <paramref name="invocation"/> on the target of this instance /// if the targetType of this instance matches the invocation, otherwise the invocation /// is passed to the next <see cref="IInvokable"/> specified in the constructor. /// </summary> /// <param name="invocation">The invocation.</param> public void Invoke(Invocation invocation) { if (targetType == invocation.Method.DeclaringType) { invocation.InvokeOn(target); } else { next.Invoke(invocation); } }
public void CanBeInvokedOnAnotherObject() { string input = "INPUT"; string output = "OUTPUT"; string result = "RESULT"; invocation = new Invocation(receiver, FOO_METHOD, new object[] {input, null}); var mockFoo = new MockFoo(); mockFoo.Foo_ExpectedInput = input; mockFoo.Foo_Output = output; mockFoo.Foo_Result = result; invocation.InvokeOn(mockFoo); Assert.IsTrue(mockFoo.FooWasInvoked, "Foo should have been invoked"); Assert.AreEqual(invocation.Result, result, "result"); Assert.AreEqual(invocation.Parameters[1], output, "output"); }