public void ValidInvocation() { /* * Target target = new Target(); * MockRepository repository = new MockRepository(); * IMethodInterceptor interceptor = (IMethodInterceptor) repository.CreateMock(typeof (IMethodInterceptor)); * AbstractMethodInvocation join = CreateMethodInvocation( * null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new object[] { interceptor }); * Expect.Call(interceptor.Invoke(join)).Return(target.BullseyeMethod().ToLower(CultureInfo.InvariantCulture)); * repository.ReplayAll(); * string score = (string) join.Proceed(); * Assert.AreEqual(target.BullseyeMethod().ToLower(CultureInfo.InvariantCulture) + Target.Suffix, score); * repository.VerifyAll(); */ Target target = new Target(); IMethodInterceptor mock = (IMethodInterceptor)mocks.CreateMock(typeof(IMethodInterceptor)); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new object[] { mock }); Expect.Call(mock.Invoke(null)).IgnoreArguments().Return(target.BullseyeMethod().ToLower(CultureInfo.InvariantCulture)); mocks.ReplayAll(); string score = (string)join.Proceed(); Assert.AreEqual(Target.DefaultScore.ToLower(CultureInfo.InvariantCulture) + Target.Suffix, score); mocks.VerifyAll(); }
public void ToStringWithArguments() { Target target = new Target(); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethod(), null, new string[] { "Five" }, target.GetType(), new ArrayList()); CheckToStringDoesntThrowAnException(join); }
public void ProceedWithEmptyInterceptorChain() { Target target = new Target(); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new ArrayList()); string score = (string)join.Proceed(); Assert.AreEqual(Target.DefaultScore + Target.Suffix, score); }
public void ToStringMustNotInvokeToStringOnTarget() { Target target = new TargetWithBadToString(); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new ArrayList()); // if it hits the target the test will fail with NotSupportedException... CheckToStringDoesntThrowAnException(join); }
public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException() { BadCommand target = new BadCommand(); IMethodInterceptor mock = A.Fake <IMethodInterceptor>(); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock }); A.CallTo(() => mock.Invoke(null)).WithAnyArguments().Throws <NotImplementedException>(); // we want this exception to bubble up... Assert.Throws <NotImplementedException>(() => join.Proceed()); }
public void UnwrapsTargetInvocationException_NoInterceptors() { BadCommand target = new BadCommand(); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { }); try { join.Proceed(); } catch (NotImplementedException) { // this is good, we want this exception to bubble up... } catch (TargetInvocationException) { Assert.Fail("Must have unwrapped this."); } }
public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException() { BadCommand target = new BadCommand(); IMethodInterceptor mock = (IMethodInterceptor)mocks.CreateMock(typeof(IMethodInterceptor)); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock }); Expect.Call(mock.Invoke(null)).IgnoreArguments().Throw(new NotImplementedException()); mocks.ReplayAll(); try { join.Proceed(); } catch (NotImplementedException) { // this is good, we want this exception to bubble up... } catch (TargetInvocationException) { Assert.Fail("Must have unwrapped this."); } mocks.VerifyAll(); }
private static string CheckToStringDoesntThrowAnException(AbstractMethodInvocation join) { return(join.ToString()); }
private static string CheckToStringDoesntThrowAnException(AbstractMethodInvocation join) { return join.ToString(); }