예제 #1
0
        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));
        }
예제 #2
0
 internal MethodSetup FindCompatibleMethodSetup(MethodCallMatcher matcher)
 {
     return(MethodSetups
            .SingleOrDefault(x => x.IsCompatible(matcher)));
 }