protected override object Invoke(MethodInfo targetMethod, object[] args) { var methodCall = ProxyMethodCall.From(this, targetMethod, args); // TODO: CQS broken? // TODO: Move CurrentMethod & ArgumentMatchers back to context? var methodCallMatcher = ThreadLocalContext.SetCurrentMethodCall(methodCall); var activeAssertion = ThreadLocalContext.ConsumeAssertion(); if (activeAssertion != null) { activeAssertion.Check( new AssertionCall(this, methodCallMatcher.Method, methodCallMatcher.ArgumentMatchers), _methodCallHistory); } else { _methodCallHistory.AddCall(methodCall); var recordedCall = MethodSetups.FirstOrDefault(m => m.MatchesCall(methodCall)); if (recordedCall != null) { var result = recordedCall.InvokeBehaviour(methodCall.PassedArguments); // TODO: is this if needed? if (!object.ReferenceEquals(result, MethodSetup.NO_RESULT)) { return(result); } } } return(ReflectionUtils.CreateDefaultValue(targetMethod.ReturnType)); }
internal MethodSetup FindCompatibleMethodSetup(MethodCallMatcher matcher) { return(MethodSetups .SingleOrDefault(x => x.IsCompatible(matcher))); }