Exemplo n.º 1
0
 public void Clear()
 {
     _currentMethodCall        = null;
     _methodCallMatcherBuilder = MethodCallMatcherBuilder.Create();
     _methodCallMatcher        = null;
     _activeAssertion          = null;
 }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public MethodCallMatcher SetCurrentMethodCall(ProxyMethodCall methodCall)
        {
            _currentMethodCall = methodCall;
            _methodCallMatcher = _methodCallMatcherBuilder
                                 .WithMethodCall(methodCall)
                                 .Build();

            _methodCallMatcherBuilder = MethodCallMatcherBuilder.Create();
            return(_methodCallMatcher);
        }
Exemplo n.º 4
0
 internal void MarkMethodCallAsSetup(ProxyMethodCall call)
 {
     _methodCallHistory.RemoveCall(call);
 }
Exemplo n.º 5
0
 public bool MatchesCall(ProxyMethodCall call)
 {
     return(_methodCallMatcher.MatchesCall(call));
 }
 public void AddCall(ProxyMethodCall methodCall)
 => _receivedCalls.Add(methodCall);
 public void RemoveCall(ProxyMethodCall methodCall)
 => _receivedCalls.Remove(methodCall);
Exemplo n.º 8
0
 public static MethodCallMatcher SetCurrentMethodCall(ProxyMethodCall methodCall)
 => _context.Value.SetCurrentMethodCall(methodCall);
 public MethodCallMatcherBuilder WithMethodCall(ProxyMethodCall methodCall)
 {
     _methodCall = methodCall;
     return(this);
 }
Exemplo n.º 10
0
 public MissingArgumentMatcherPlaceholder(ProxyMethodCall methodCall, int argumentPosition)
 {
     this.InvalidMatcherUsageMessage = CreateMessage(methodCall, argumentPosition);
 }