Esempio n. 1
0
 public ConfiguredCall SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs)
 {
     var spec = _getCallSpec.FromPendingSpecification(matchArgs);
     CheckResultIsCompatibleWithCall(valueToReturn, spec);
     _configuredResults.SetResult(spec, valueToReturn);
     return new ConfiguredCall(action => _callActions.Add(spec, action));
 }
 public SetActionForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallActions callActions, Action<CallInfo> action, MatchArgs matchArgs)
 {
     _callSpecificationFactory = callSpecificationFactory;
     _callActions = callActions;
     _action = action;
     _matchArgs = matchArgs;
 }
 public CheckDidNotReceiveCallHandler(IReceivedCalls receivedCalls, ICallSpecificationFactory callSpecificationFactory, ICallReceivedExceptionThrower exceptionThrower, MatchArgs matchArgs)
 {
     _receivedCalls = receivedCalls;
     _callSpecificationFactory = callSpecificationFactory;
     _exceptionThrower = exceptionThrower;
     _matchArgs = matchArgs;
 }
 public CheckReceivedCallsHandler(IReceivedCalls receivedCalls, ICallSpecificationFactory callSpecificationFactory, IReceivedCallsExceptionThrower exceptionThrower, MatchArgs matchArgs, Quantity requiredQuantity)
 {
     _receivedCalls = receivedCalls;
     _callSpecificationFactory = callSpecificationFactory;
     _exceptionThrower = exceptionThrower;
     _matchArgs = matchArgs;
     _requiredQuantity = requiredQuantity;
 }
 public IRoute DoWhenCalled(ISubstituteState state, Action<CallInfo> doAction, MatchArgs matchArgs)
 {
     return new Route(new ICallHandler[] {
         new ClearLastCallRouterHandler(state.SubstitutionContext)
         , new ClearUnusedCallSpecHandler(state)
         , new SetActionForCallHandler(state.CallSpecificationFactory, state.CallActions, doAction, matchArgs)
         , ReturnDefaultForReturnTypeHandler()
     });
 }
Esempio n. 6
0
 public IRoute DoNotCallBase(ISubstituteState state, MatchArgs matchArgs)
 {
     return new Route(new ICallHandler[] {
         new ClearLastCallRouterHandler(state.SubstitutionContext)
         , new ClearUnusedCallSpecHandler(state.PendingSpecification)
         , new DoNotCallBaseForCallHandler(state.CallSpecificationFactory, state.CallBaseExclusions, matchArgs)
         , ReturnDefaultForReturnTypeHandler()
     });
 }
 public ICallSpecification CreateFrom(ICall call, MatchArgs matchArgs)
 {
     var methodInfo = call.GetMethodInfo();
     var argumentSpecs = call.GetArgumentSpecifications();
     var arguments = call.GetOriginalArguments();
     var parameterInfos = call.GetParameterInfos();
     var argumentSpecificationsForCall = _argumentSpecificationsFactory.Create(argumentSpecs, arguments, parameterInfos, matchArgs);
     return new CallSpecification(methodInfo, argumentSpecificationsForCall);
 }
Esempio n. 8
0
 public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null)
     {
         throw new CouldNotSetReturnException();
     }
     _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     _lastCallRouter.Value = null;
 }
 public IRoute CheckReceivedCalls(ISubstituteState state, MatchArgs matchArgs, Quantity requiredQuantity)
 {
     return new Route(new ICallHandler[] {
         new ClearLastCallRouterHandler(state.SubstitutionContext)
         , new ClearUnusedCallSpecHandler(state)
         , new CheckReceivedCallsHandler(state.ReceivedCalls, state.CallSpecificationFactory, new ReceivedCallsExceptionThrower(), matchArgs, requiredQuantity)
         , ReturnDefaultForReturnTypeHandler()
     });
 }
Esempio n. 10
0
 public ICallSpecification FromPendingSpecification(MatchArgs matchArgs, PendingSpecificationInfo pendingSpecInfo)
 {
     return(pendingSpecInfo.Handle(
                callSpec => FromExistingSpec(callSpec, matchArgs),
                lastCall =>
     {
         _receivedCalls.Delete(lastCall);
         return FromCall(lastCall, matchArgs);
     }));
 }
Esempio n. 11
0
 public IRoute CheckReceivedCalls(ISubstituteState state, MatchArgs matchArgs, Quantity requiredQuantity)
 {
     return new Route(new ICallHandler[] {
         new ClearLastCallRouterHandler(state.SubstitutionContext)
         , new ClearUnusedCallSpecHandler(state.PendingSpecification)
         , new CheckReceivedCallsHandler(state.ReceivedCalls, state.CallSpecificationFactory, new ReceivedCallsExceptionThrower(), matchArgs, requiredQuantity)
         , new ReturnAutoValue(AutoValueBehaviour.ReturnAndForgetValue, state.AutoValueProviders, state.AutoValuesCallResults, state.CallSpecificationFactory)
         , ReturnDefaultForReturnTypeHandler()
     });
 }
Esempio n. 12
0
        public ICallSpecification CreateFrom(ICall call, MatchArgs matchArgs)
        {
            var methodInfo     = call.GetMethodInfo();
            var argumentSpecs  = call.GetArgumentSpecifications();
            var arguments      = call.GetOriginalArguments();
            var parameterInfos = call.GetParameterInfos();
            var argumentSpecificationsForCall = _argumentSpecificationsFactory.Create(argumentSpecs, arguments, parameterInfos, methodInfo, matchArgs);

            return(new CallSpecification(methodInfo, argumentSpecificationsForCall));
        }
        public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
        {
            if (_lastCallRouter.Value == null)
            {
                throw new CouldNotSetReturnDueToNoLastCallException();
            }
            var configuredCall = _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);

            ClearLastCallRouter();
            return(configuredCall);
        }
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null) throw new CouldNotSetReturnDueToNoLastCallException();
     if (_argumentSpecifications.Value.Any())
     {
         //Clear invalid arg specs so they will not affect other tests
         _argumentSpecifications.Value.Clear();
         throw new UnexpectedArgumentMatcherException();
     }
     var configuredCall = _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     ClearLastCallRouter();
     return configuredCall;
 }
Esempio n. 15
0
        public ICallSpecification FromPendingSpecification(MatchArgs matchArgs, PendingSpecificationInfo pendingSpecInfo)
        {
            if (pendingSpecInfo == null)
            {
                throw new ArgumentNullException(nameof(pendingSpecInfo));
            }

            return(pendingSpecInfo.Handle(
                       callSpec => FromExistingSpec(callSpec, matchArgs),
                       lastCall =>
            {
                _receivedCalls.Delete(lastCall);
                return FromCall(lastCall, matchArgs);
            }));
        }
Esempio n. 16
0
        public ICallSpecification FromPendingSpecification(MatchArgs matchArgs)
        {
            if (!_pendingSpecification.HasPendingCallSpecInfo())
            {
                throw new InvalidOperationException("No pending specification or previous call info.");
            }

            var pendingSpecInfo = _pendingSpecification.UseCallSpecInfo();
            return pendingSpecInfo.Handle(
                callSpec => FromExistingSpec(callSpec, matchArgs),
                lastCall =>
                {
                    _callCollection.Delete(lastCall);
                    return FromCall(lastCall, matchArgs);
                });
        }
        public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
        {
            if (_lastCallRouter.Value == null)
            {
                throw new CouldNotSetReturnDueToNoLastCallException();
            }
            if (_argumentSpecifications.Value.Any())
            {
                //Clear invalid arg specs so they will not affect other tests
                _argumentSpecifications.Value.Clear();
                throw new UnexpectedArgumentMatcherException();
            }
            var configuredCall = _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);

            ClearLastCallRouter();
            return(configuredCall);
        }
Esempio n. 18
0
        public ICallSpecification FromPendingSpecification(MatchArgs matchArgs)
        {
            if (!_pendingSpecification.HasPendingCallSpecInfo())
            {
                throw new InvalidOperationException("No pending specification or previous call info.");
            }

            var pendingSpecInfo = _pendingSpecification.UseCallSpecInfo();

            return(pendingSpecInfo.Handle(
                       callSpec => FromExistingSpec(callSpec, matchArgs),
                       lastCall =>
            {
                _callCollection.Delete(lastCall);
                return FromCall(lastCall, matchArgs);
            }));
        }
Esempio n. 19
0
        public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs, PendingSpecificationInfo pendingSpecInfo)
        {
            if (returnValue == null)
            {
                throw new ArgumentNullException(nameof(returnValue));
            }
            if (matchArgs == null)
            {
                throw new ArgumentNullException(nameof(matchArgs));
            }
            if (pendingSpecInfo == null)
            {
                throw new ArgumentNullException(nameof(pendingSpecInfo));
            }

            return(_substituteState.ConfigureCall.SetResultForLastCall(returnValue, matchArgs, pendingSpecInfo));
        }
Esempio n. 20
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return new ConfiguredCall(x => { });
 }
Esempio n. 21
0
 public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null) throw new CouldNotSetReturnException();
     _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     _lastCallRouter.Value = null;
 }
Esempio n. 22
0
 public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs)
 {
     return(matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec));
 }
Esempio n. 23
0
 public WhenCalled(ISubstitutionContext context, T substitute, Action <T> call, MatchArgs matchArgs)
 {
     _substitute = substitute;
     _call       = call;
     _matchArgs  = matchArgs;
     _callRouter = context.GetCallRouterFor(substitute);
 }
Esempio n. 24
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return ConfigureCall.SetResultForLastCall(returnValue, matchArgs);
 }
Esempio n. 25
0
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs) =>
 ThreadContext.LastCallShouldReturn(value, matchArgs);
Esempio n. 26
0
 public IRoute CallBase(ISubstituteState state, MatchArgs matchArgs) =>
 _factory.CallBase(state, matchArgs);
Esempio n. 27
0
 public void SetResultForCall(ICall call, IReturn valueToReturn, MatchArgs matchArgs)
 {
     var spec = _getCallSpec.FromCall(call, matchArgs);
     CheckResultIsCompatibleWithCall(valueToReturn, spec);
     _configuredResults.SetResult(spec, valueToReturn);
 }
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     return innerContext.LastCallShouldReturn(value, matchArgs);
 }
 public DoNotCallBaseForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallBaseExclusions exclusions, MatchArgs matchArgs)
 {
     _callSpecificationFactory = callSpecificationFactory;
     _exclusions = exclusions;
     _matchArgs = matchArgs;
 }
Esempio n. 30
0
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null) throw new CouldNotSetReturnDueToNoLastCallException();
     var configuredCall = _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     ClearLastCallRouter();
     return configuredCall;
 }
Esempio n. 31
0
 public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter == null) throw new SubstituteException();
     _lastCallRouter.LastCallShouldReturn(value, matchArgs);
 }
Esempio n. 32
0
 public IRoute CheckReceivedCalls(ISubstituteState state, MatchArgs matchArgs, Quantity requiredQuantity) =>
 _factory.CheckReceivedCalls(state, matchArgs, requiredQuantity);
Esempio n. 33
0
 public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     _resultSetter.SetResultForLastCall(returnValue, matchArgs);
 }
Esempio n. 34
0
 public IRoute DoWhenCalled(ISubstituteState state, Action <CallInfo> doAction, MatchArgs matchArgs) =>
 _factory.DoWhenCalled(state, doAction, matchArgs);
Esempio n. 35
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return(ConfigureCall.SetResultForLastCall(returnValue, matchArgs));
 }
Esempio n. 36
0
 public ICallSpecification FromCall(ICall call, MatchArgs matchArgs)
 {
     return _callSpecificationFactory.CreateFrom(call, matchArgs);
 }
Esempio n. 37
0
 public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs)
 {
     return matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec);
 }
Esempio n. 38
0
 public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     _resultSetter.SetResultForLastCall(returnValue, matchArgs);
 }
Esempio n. 39
0
 public ICallSpecification FromCall(ICall call, MatchArgs matchArgs)
 {
     return(_callSpecificationFactory.CreateFrom(call, matchArgs));
 }
Esempio n. 40
0
 public WhenCalled(ISubstitutionContext context, T substitute, Action <T> call, MatchArgs matchArgs)
 {
     _substitute    = substitute;
     _call          = call;
     _matchArgs     = matchArgs;
     _callRouter    = context.GetCallRouterFor(substitute !);
     _routeFactory  = context.RouteFactory;
     _threadContext = context.ThreadContext;
 }
Esempio n. 41
0
 public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
 }