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; }
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 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() })); }
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() })); }
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() })); }
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); }
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); }
public static void Invoke(MatchArgs matchMade) { if (matchMade != null) { latestMatch = matchMade; } foreach (MatchMadeEvent matchEvent in FindObjectsOfType <MatchMadeEvent>()) { matchEvent.ExecuteBlock(); } }
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>"); }
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)); }
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); }
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)); }
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)); }
public ICallSpecification FromCall(ICall call, MatchArgs matchArgs) { return _callSpecificationFactory.CreateFrom(call, matchArgs); }
public ICallSpecification FromExistingSpec(ICallSpecification spec, MatchArgs matchArgs) { return matchArgs == MatchArgs.AsSpecifiedInCall ? spec : UpdateCallSpecToMatchAnyArgs(spec); }
public DoNotCallBaseForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallBaseExclusions exclusions, MatchArgs matchArgs) { _callSpecificationFactory = callSpecificationFactory; _exclusions = exclusions; _matchArgs = matchArgs; }
public ICallSpecification FromLastCall(MatchArgs matchArgs) { return _pendingSpecification.HasPendingCallSpec() ? FromExistingSpec(_pendingSpecification.UseCallSpec(), matchArgs) : FromCall(_callStack.Pop(), matchArgs); }
public WhenCalledAny(ISubstitutionContext context, T substitute, Action <T> call, MatchArgs matchArgs) : base(context, substitute, call, matchArgs) { }
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)); }
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)); }
ICallSpecification GetCallSpecForArgMatchStrategy(ICallSpecification callSpecification, MatchArgs matchArgs) { return matchArgs == MatchArgs.AsSpecifiedInCall ? callSpecification : UpdateCallSpecToMatchAnyArgs(callSpecification); }
public SetActionForCallHandler(ICallSpecificationFactory callSpecificationFactory, ICallActions callActions, Action <CallInfo> action, MatchArgs matchArgs) { _callSpecificationFactory = callSpecificationFactory; _callActions = callActions; _action = action; _matchArgs = matchArgs; }
void SetResultForCall(ICallSpecification callSpecification, IReturn valueToReturn, MatchArgs matchArgs) { var callSpecForReturnValue = GetCallSpecForArgMatchStrategy(callSpecification, matchArgs); _configuredResults.SetResult(callSpecForReturnValue, valueToReturn); }
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)); }
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)); }
public CheckReceivedCallsHandler(IReceivedCalls receivedCalls, ICallSpecificationFactory callSpecificationFactory, IReceivedCallsExceptionThrower exceptionThrower, MatchArgs matchArgs, Quantity requiredQuantity) { _receivedCalls = receivedCalls; _callSpecificationFactory = callSpecificationFactory; _exceptionThrower = exceptionThrower; _matchArgs = matchArgs; _requiredQuantity = requiredQuantity; }
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)); }
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() })); }
public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs, PendingSpecificationInfo pendingSpecInfo) => throw new NotImplementedException();
public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) { return(new ConfiguredCall(x => { })); }