public IEnumerable<IArgumentSpecification> Create(IList<IArgumentSpecification> argumentSpecs, object[] arguments, IParameterInfo[] parameterInfos, MatchArgs matchArgs)
        {
            if (matchArgs == MatchArgs.Any) return parameterInfos.Select(x => (IArgumentSpecification) new ArgumentIsAnythingSpecification(x.ParameterType));

            if (argumentSpecs.Count == arguments.Length) return argumentSpecs;

            return MixedArgumentSpecificationsFactory.Create(argumentSpecs, arguments, parameterInfos);
        }
        public IEnumerable<IArgumentSpecification> Create(IList<IArgumentSpecification> argumentSpecs, object[] arguments, IParameterInfo[] parameterInfos, MatchArgs matchArgs)
        {
            var argumentSpecifications = _mixedArgumentSpecificationsFactory.Create(argumentSpecs, arguments, parameterInfos);

            return (matchArgs == MatchArgs.Any) 
                ? argumentSpecifications.Select(x => x.CreateCopyMatchingAnyArgOfType(x.ForType))
                : argumentSpecifications;
        }
Example #3
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()
     }));
 }
Example #4
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()
     }));
 }
Example #5
0
 public IRoute CallBase(ISubstituteState state, MatchArgs matchArgs)
 {
     return(new Route(new ICallHandler[] {
         new ClearLastCallRouterHandler(_threadLocalContext)
         , new ClearUnusedCallSpecHandler(_threadLocalContext.PendingSpecification)
         , new CallBaseForCallHandler(_callSpecificationFactory, state.CallBaseConfiguration, matchArgs)
         , ReturnDefaultForReturnTypeHandler()
     }));
 }
Example #6
0
 public IRoute CheckReceivedCalls(ISubstituteState state, MatchArgs matchArgs, Quantity requiredQuantity)
 {
     return(new Route(new ICallHandler[] {
         new ClearLastCallRouterHandler(_threadLocalContext)
         , new ClearUnusedCallSpecHandler(_threadLocalContext.PendingSpecification)
         , new CheckReceivedCallsHandler(state.ReceivedCalls, _callSpecificationFactory, _receivedCallsExceptionThrower, matchArgs, requiredQuantity)
         , new ReturnAutoValue(AutoValueBehaviour.ReturnAndForgetValue, state.AutoValueProviders, state.AutoValuesCallResults, _callSpecificationFactory)
         , ReturnDefaultForReturnTypeHandler()
     }));
 }
Example #7
0
            public override void Context()
            {
                _call        = mock <ICall>();
                _action      = args => { };
                _callActions = mock <ICallActions>();
                _callSpec    = mock <ICallSpecification>();
                _matchArgs   = MatchArgs.AsSpecifiedInCall;

                _callSpecificationFactory = mock <ICallSpecificationFactory>();
                _callSpecificationFactory.stub(x => x.CreateFrom(_call, _matchArgs)).Return(_callSpec);
            }
Example #8
0
            public override void Context()
            {
                _call = mock <Action <IFoo> >();
                _callbackWithArguments = args => { };
                _matchArgs             = MatchArgs.AsSpecifiedInCall;

                _context    = mock <ISubstitutionContext>();
                _substitute = mock <IFoo>();
                _callRouter = mock <ICallRouter>();

                _context.stub(x => x.GetCallRouterFor(_substitute)).Return(_callRouter);
            }
Example #9
0
    public static void Invoke(MatchArgs matchMade)
    {
        if (matchMade != null)
        {
            latestMatch = matchMade;
        }

        foreach (MatchMadeEvent matchEvent in FindObjectsOfType <MatchMadeEvent>())
        {
            matchEvent.ExecuteBlock();
        }
    }
Example #10
0
 public void SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs)
 {
     if (_pendingSpecification.HasPendingCallSpec())
     {
         SetResultForCall(_pendingSpecification.UseCallSpec(), valueToReturn, matchArgs);
     }
     else
     {
         var lastCall = _callStack.Pop();
         SetResultForCall(lastCall, valueToReturn, matchArgs);
     }
 }
        public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs,
                                                   PendingSpecificationInfo pendingSpecInfo)
        {
            Trace($"LastCallShouldReturn(value: {returnValue.DiagName(_ctx)}, " +
                  $"matchArgs: {matchArgs.DiagName()}, pendingSpecInfo: {pendingSpecInfo.DiagName(_ctx)})");
            Log($"[Configure last call] " +
                $"CallSpecification: {pendingSpecInfo.DiagName(_ctx)} " +
                $"Value: {returnValue.DiagName(_ctx)} " +
                $"Match: {matchArgs.DiagName()} ");

            return(_impl.LastCallShouldReturn(returnValue, matchArgs, pendingSpecInfo));
        }
 public static string DiagName(this MatchArgs matchArgs)
 {
     if (matchArgs == MatchArgs.Any)
     {
         return("<any>");
     }
     if (matchArgs == MatchArgs.AsSpecifiedInCall)
     {
         return("<as specified>");
     }
     return("<unknown>");
 }
Example #13
0
 public void SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs)
 {
     if (_pendingSpecification.HasPendingCallSpec())
     {
         SetResultForCall(_pendingSpecification.UseCallSpec(), valueToReturn, matchArgs);
     }
     else
     {
         var lastCall = _callStack.Pop();
         SetResultForCall(lastCall, valueToReturn, matchArgs);
     }
 }
        internal static ConfiguredCall Returns <T>(MatchArgs matchArgs, T returnThis, params T[] returnThese)
        {
            var     context = SubstitutionContext.Current;
            IReturn returnValue;

            if (returnThese == null || returnThese.Length == 0)
            {
                returnValue = new ReturnValue(returnThis);
            }
            else
            {
                returnValue = new ReturnMultipleValues <T>(new[] { returnThis }.Concat(returnThese).ToArray());
            }
            return(context.LastCallShouldReturn(returnValue, matchArgs));
        }
Example #15
0
        private static void Returns <T>(MatchArgs matchArgs, T returnThis, params T[] returnThese)
        {
            var     context = SubstitutionContext.Current;
            IReturn returnValue;

            if (returnThese == null || returnThese.Length == 0)
            {
                returnValue = new ReturnValue(returnThis);
            }
            else
            {
                returnValue = new ReturnMultipleValues <T>(new[] { returnThis }.Concat(returnThese));
            }
            context.LastCallShouldReturn(returnValue, matchArgs);
        }
Example #16
0
        private static ConfiguredCall Returns <T>(MatchArgs matchArgs, Func <CallInfo, T> returnThis, params Func <CallInfo, T>[] returnThese)
        {
            var     context = SubstitutionContext.Current;
            IReturn returnValue;

            if (returnThese == null || returnThese.Length == 0)
            {
                returnValue = new ReturnValueFromFunc <T>(returnThis);
            }
            else
            {
                returnValue = new ReturnMultipleFuncsValues <T>(new[] { returnThis }.Concat(returnThese));
            }

            return(context.LastCallShouldReturn(returnValue, matchArgs));
        }
Example #17
0
        private static ConfiguredCall ConfigureReturn <T>(MatchArgs matchArgs, T returnThis, T[] returnThese)
        {
            IReturn returnValue;

            if (returnThese == null || returnThese.Length == 0)
            {
                returnValue = new ReturnValue(returnThis);
            }
            else
            {
                returnValue = new ReturnMultipleValues <T>(new[] { returnThis }.Concat(returnThese).ToArray());
            }
            return(SubstitutionContext
                   .Current
                   .ThreadContext
                   .LastCallShouldReturn(returnValue, matchArgs));
        }
Example #18
0
 public ICallSpecification FromCall(ICall call, MatchArgs matchArgs)
 {
     return _callSpecificationFactory.CreateFrom(call, matchArgs);
 }
Example #19
0
 public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs)
 {
     return matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec);
 }
Example #20
0
 public DoNotCallBaseForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallBaseExclusions exclusions, MatchArgs matchArgs)
 {
     _callSpecificationFactory = callSpecificationFactory;
     _exclusions = exclusions;
     _matchArgs  = matchArgs;
 }
Example #21
0
 public ICallSpecification FromLastCall(MatchArgs matchArgs)
 {
     return _pendingSpecification.HasPendingCallSpec()
                        ? FromExistingSpec(_pendingSpecification.UseCallSpec(), matchArgs)
                        : FromCall(_callStack.Pop(), matchArgs);
 }
Example #22
0
 public WhenCalledAny(ISubstitutionContext context, T substitute, Action <T> call, MatchArgs matchArgs)
     : base(context, substitute, call, matchArgs)
 {
 }
Example #23
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) =>
 throw new NotImplementedException();
 public ICallSpecification FromLastCall(MatchArgs matchArgs)
 {
     return(_pendingSpecification.HasPendingCallSpec()
                        ? FromExistingSpec(_pendingSpecification.UseCallSpec(), matchArgs)
                        : FromCall(_callStack.Pop(), matchArgs));
 }
Example #25
0
 public void SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs)
 {
     var lastCall = _callStack.Pop();
     SetResultForCall(lastCall, valueToReturn, matchArgs);
 }
 public DoNotCallBaseForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallBaseConfiguration callBaseConfig, MatchArgs matchArgs)
 {
     _callSpecificationFactory = callSpecificationFactory ?? throw new ArgumentNullException(nameof(callSpecificationFactory));
     _callBaseConfig           = callBaseConfig ?? throw new ArgumentNullException(nameof(callBaseConfig));
     _matchArgs = matchArgs ?? throw new ArgumentNullException(nameof(matchArgs));
 }
Example #27
0
 ICallSpecification GetCallSpecForArgMatchStrategy(ICallSpecification callSpecification, MatchArgs matchArgs)
 {
     return matchArgs == MatchArgs.AsSpecifiedInCall ? callSpecification : UpdateCallSpecToMatchAnyArgs(callSpecification);
 }
Example #28
0
 public SetActionForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallActions callActions, Action <CallInfo> action, MatchArgs matchArgs)
 {
     _callSpecificationFactory = callSpecificationFactory;
     _callActions = callActions;
     _action      = action;
     _matchArgs   = matchArgs;
 }
Example #29
0
 void SetResultForCall(ICallSpecification callSpecification, IReturn valueToReturn, MatchArgs matchArgs)
 {
     var callSpecForReturnValue = GetCallSpecForArgMatchStrategy(callSpecification, matchArgs);
     _configuredResults.SetResult(callSpecForReturnValue, valueToReturn);
 }
Example #30
0
        public IEnumerable <IArgumentSpecification> Create(IList <IArgumentSpecification> argumentSpecs, object[] arguments, IParameterInfo[] parameterInfos, MethodInfo methodInfo, MatchArgs matchArgs)
        {
            var suppliedArgumentSpecifications = _suppliedArgumentSpecificationsFactory.Create(argumentSpecs);

            var result = new List <IArgumentSpecification>();

            for (var i = 0; i < arguments.Length; i++)
            {
                var arg       = arguments[i];
                var paramInfo = parameterInfos[i];

                try
                {
                    result.Add(_argumentSpecificationFactory.Create(arg, paramInfo, suppliedArgumentSpecifications));
                }
                catch (AmbiguousArgumentsException ex) when(ex.ContainsDefaultMessage)
                {
                    IEnumerable <IArgumentSpecification> alreadyResolvedSpecs = result;

                    if (ex.Data[AmbiguousArgumentsException.NonReportedResolvedSpecificationsKey] is IEnumerable <IArgumentSpecification> additional)
                    {
                        alreadyResolvedSpecs = alreadyResolvedSpecs.Concat(additional);
                    }

                    throw new AmbiguousArgumentsException(methodInfo, arguments, alreadyResolvedSpecs, argumentSpecs);
                }
            }

            var remainingArgumentSpecifications = suppliedArgumentSpecifications.DequeueRemaining();

            if (remainingArgumentSpecifications.Any())
            {
                throw new RedundantArgumentMatcherException(remainingArgumentSpecifications, argumentSpecs);
            }

            return(matchArgs == MatchArgs.Any
                ? ConvertToMatchAnyValue(result)
                : result);
        }
 public DoNotCallBaseForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallBaseConfiguration callBaseConfig, MatchArgs matchArgs)
 {
     _callSpecificationFactory = callSpecificationFactory;
     _callBaseConfig           = callBaseConfig;
     _matchArgs = matchArgs;
 }
 public ICallSpecification FromCall(ICall call, MatchArgs matchArgs)
 {
     return(_callSpecificationFactory.CreateFrom(call, matchArgs));
 }
Example #33
0
        public IEnumerable <IArgumentSpecification> Create(IList <IArgumentSpecification> argumentSpecs, object[] arguments, IParameterInfo[] parameterInfos, MatchArgs matchArgs)
        {
            var argumentSpecifications = _mixedArgumentSpecificationsFactory.Create(argumentSpecs, arguments, parameterInfos);

            return((matchArgs == MatchArgs.Any)
                ? argumentSpecifications.Select(x => x.CreateCopyMatchingAnyArgOfType(x.ForType))
                : argumentSpecifications);
        }
 public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs)
 {
     return(matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec));
 }
Example #35
0
 public CheckReceivedCallsHandler(IReceivedCalls receivedCalls, ICallSpecificationFactory callSpecificationFactory, IReceivedCallsExceptionThrower exceptionThrower, MatchArgs matchArgs, Quantity requiredQuantity)
 {
     _receivedCalls            = receivedCalls;
     _callSpecificationFactory = callSpecificationFactory;
     _exceptionThrower         = exceptionThrower;
     _matchArgs        = matchArgs;
     _requiredQuantity = requiredQuantity;
 }
Example #36
0
 public void SetResultForCall(ICall call, IReturn valueToReturn, MatchArgs matchArgs)
 {
     var callSpecification = _callSpecificationFactory.CreateFrom(call, matchArgs);
     _configuredResults.SetResult(callSpecification, valueToReturn);
 }
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     Trace($"LastCallShouldReturn(value: {value.DiagName(_ctx)}, matchArgs: {matchArgs.DiagName()})");
     return(_impl.LastCallShouldReturn(value, matchArgs));
 }
Example #38
0
 public IRoute DoWhenCalled(ISubstituteState state, Action <CallInfo> doAction, MatchArgs matchArgs)
 {
     return(new Route(new ICallHandler[] {
         new ClearLastCallRouterHandler(_threadLocalContext)
         , new ClearUnusedCallSpecHandler(_threadLocalContext.PendingSpecification)
         , new SetActionForCallHandler(_callSpecificationFactory, state.CallActions, doAction, matchArgs)
         , ReturnDefaultForReturnTypeHandler()
     }));
 }
Example #39
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs, PendingSpecificationInfo pendingSpecInfo) =>
 throw new NotImplementedException();
Example #40
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return(new ConfiguredCall(x => { }));
 }