예제 #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;
 }
예제 #5
0
 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()
     });
 }
예제 #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);
 }
예제 #8
0
 public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null)
     {
         throw new CouldNotSetReturnException();
     }
     _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     _lastCallRouter.Value = null;
 }
예제 #9
0
 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()
     });
 }
예제 #10
0
 public ICallSpecification FromPendingSpecification(MatchArgs matchArgs, PendingSpecificationInfo pendingSpecInfo)
 {
     return(pendingSpecInfo.Handle(
                callSpec => FromExistingSpec(callSpec, matchArgs),
                lastCall =>
     {
         _receivedCalls.Delete(lastCall);
         return FromCall(lastCall, matchArgs);
     }));
 }
예제 #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()
     });
 }
예제 #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);
        }
예제 #14
0
 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;
 }
예제 #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);
            }));
        }
예제 #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);
                });
        }
예제 #17
0
        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);
        }
예제 #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);
            }));
        }
예제 #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));
        }
예제 #20
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return new ConfiguredCall(x => { });
 }
예제 #21
0
 public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null) throw new CouldNotSetReturnException();
     _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     _lastCallRouter.Value = null;
 }
예제 #22
0
 public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs)
 {
     return(matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec));
 }
예제 #23
0
 public WhenCalled(ISubstitutionContext context, T substitute, Action <T> call, MatchArgs matchArgs)
 {
     _substitute = substitute;
     _call       = call;
     _matchArgs  = matchArgs;
     _callRouter = context.GetCallRouterFor(substitute);
 }
예제 #24
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return ConfigureCall.SetResultForLastCall(returnValue, matchArgs);
 }
예제 #25
0
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs) =>
 ThreadContext.LastCallShouldReturn(value, matchArgs);
예제 #26
0
 public IRoute CallBase(ISubstituteState state, MatchArgs matchArgs) =>
 _factory.CallBase(state, matchArgs);
예제 #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;
 }
예제 #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;
 }
예제 #31
0
 public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter == null) throw new SubstituteException();
     _lastCallRouter.LastCallShouldReturn(value, matchArgs);
 }
예제 #32
0
 public IRoute CheckReceivedCalls(ISubstituteState state, MatchArgs matchArgs, Quantity requiredQuantity) =>
 _factory.CheckReceivedCalls(state, matchArgs, requiredQuantity);
예제 #33
0
 public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     _resultSetter.SetResultForLastCall(returnValue, matchArgs);
 }
예제 #34
0
 public IRoute DoWhenCalled(ISubstituteState state, Action <CallInfo> doAction, MatchArgs matchArgs) =>
 _factory.DoWhenCalled(state, doAction, matchArgs);
예제 #35
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return(ConfigureCall.SetResultForLastCall(returnValue, matchArgs));
 }
예제 #36
0
 public ICallSpecification FromCall(ICall call, MatchArgs matchArgs)
 {
     return _callSpecificationFactory.CreateFrom(call, matchArgs);
 }
예제 #37
0
 public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs)
 {
     return matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec);
 }
예제 #38
0
 public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     _resultSetter.SetResultForLastCall(returnValue, matchArgs);
 }
예제 #39
0
 public ICallSpecification FromCall(ICall call, MatchArgs matchArgs)
 {
     return(_callSpecificationFactory.CreateFrom(call, matchArgs));
 }
예제 #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;
 }
예제 #41
0
 public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
 }