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;
        }
Exemplo n.º 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()
     }));
 }
Exemplo n.º 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()
     }));
 }
Exemplo n.º 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()
     }));
 }
Exemplo n.º 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()
     }));
 }
Exemplo n.º 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);
            }
Exemplo n.º 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);
            }
Exemplo n.º 9
0
    public static void Invoke(MatchArgs matchMade)
    {
        if (matchMade != null)
        {
            latestMatch = matchMade;
        }

        foreach (MatchMadeEvent matchEvent in FindObjectsOfType <MatchMadeEvent>())
        {
            matchEvent.ExecuteBlock();
        }
    }
Exemplo n.º 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>");
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 18
0
 public ICallSpecification FromCall(ICall call, MatchArgs matchArgs)
 {
     return _callSpecificationFactory.CreateFrom(call, matchArgs);
 }
Exemplo n.º 19
0
 public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs)
 {
     return matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec);
 }
Exemplo n.º 20
0
 public DoNotCallBaseForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallBaseExclusions exclusions, MatchArgs matchArgs)
 {
     _callSpecificationFactory = callSpecificationFactory;
     _exclusions = exclusions;
     _matchArgs  = matchArgs;
 }
Exemplo n.º 21
0
 public ICallSpecification FromLastCall(MatchArgs matchArgs)
 {
     return _pendingSpecification.HasPendingCallSpec()
                        ? FromExistingSpec(_pendingSpecification.UseCallSpec(), matchArgs)
                        : FromCall(_callStack.Pop(), matchArgs);
 }
Exemplo n.º 22
0
 public WhenCalledAny(ISubstitutionContext context, T substitute, Action <T> call, MatchArgs matchArgs)
     : base(context, substitute, call, matchArgs)
 {
 }
Exemplo n.º 23
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) =>
 throw new NotImplementedException();
Exemplo n.º 24
0
 public ICallSpecification FromLastCall(MatchArgs matchArgs)
 {
     return(_pendingSpecification.HasPendingCallSpec()
                        ? FromExistingSpec(_pendingSpecification.UseCallSpec(), matchArgs)
                        : FromCall(_callStack.Pop(), matchArgs));
 }
Exemplo n.º 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));
 }
Exemplo n.º 27
0
 ICallSpecification GetCallSpecForArgMatchStrategy(ICallSpecification callSpecification, MatchArgs matchArgs)
 {
     return matchArgs == MatchArgs.AsSpecifiedInCall ? callSpecification : UpdateCallSpecToMatchAnyArgs(callSpecification);
 }
Exemplo n.º 28
0
 public SetActionForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallActions callActions, Action <CallInfo> action, MatchArgs matchArgs)
 {
     _callSpecificationFactory = callSpecificationFactory;
     _callActions = callActions;
     _action      = action;
     _matchArgs   = matchArgs;
 }
Exemplo n.º 29
0
 void SetResultForCall(ICallSpecification callSpecification, IReturn valueToReturn, MatchArgs matchArgs)
 {
     var callSpecForReturnValue = GetCallSpecForArgMatchStrategy(callSpecification, matchArgs);
     _configuredResults.SetResult(callSpecForReturnValue, valueToReturn);
 }
Exemplo n.º 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;
 }
Exemplo n.º 32
0
 public ICallSpecification FromCall(ICall call, MatchArgs matchArgs)
 {
     return(_callSpecificationFactory.CreateFrom(call, matchArgs));
 }
Exemplo n.º 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);
        }
Exemplo n.º 34
0
 public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs)
 {
     return(matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec));
 }
Exemplo n.º 35
0
 public CheckReceivedCallsHandler(IReceivedCalls receivedCalls, ICallSpecificationFactory callSpecificationFactory, IReceivedCallsExceptionThrower exceptionThrower, MatchArgs matchArgs, Quantity requiredQuantity)
 {
     _receivedCalls            = receivedCalls;
     _callSpecificationFactory = callSpecificationFactory;
     _exceptionThrower         = exceptionThrower;
     _matchArgs        = matchArgs;
     _requiredQuantity = requiredQuantity;
 }
Exemplo n.º 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));
 }
Exemplo n.º 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()
     }));
 }
Exemplo n.º 39
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs, PendingSpecificationInfo pendingSpecInfo) =>
 throw new NotImplementedException();
Exemplo n.º 40
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return(new ConfiguredCall(x => { }));
 }