public ICallRouter Create(ISubstituteState substituteState, bool canConfigureBaseCalls) { // Cache popular routes which are bound to the particular substitute state when it's possible. var factoryWithCachedRoutes = new RouteFactoryCacheWrapper(_routeFactory); return(new CallRouter(substituteState, _threadLocalContext, factoryWithCachedRoutes, canConfigureBaseCalls)); }
public CallRouter(ISubstituteState substituteState, IThreadLocalContext threadContext, IRouteFactory routeFactory, bool canConfigureBaseCalls) { _substituteState = substituteState; _threadContext = threadContext; _routeFactory = routeFactory; _canConfigureBaseCalls = canConfigureBaseCalls; }
public CallRouter(ISubstituteState substituteState, IThreadLocalContext threadContext, IRouteFactory routeFactory) { _substituteState = substituteState; _threadContext = threadContext; _routeFactory = routeFactory; UseDefaultRouteForNextCall(); }
public ICallHandler CreateCallHandler(Type handlerType, ISubstituteState substituteState, object[] routeArguments) { var constructor = GetConstructorFor(handlerType); var parameterTypes = constructor.GetParameters().Select(x => x.ParameterType); var parameters = GetParameters(parameterTypes, substituteState, routeArguments); return((ICallHandler)constructor.Invoke(parameters)); }
public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory) { _substituteState = substituteState; _context = context; _routeFactory = routeFactory; UseDefaultRouteForNextCall(); }
public IRoute RaiseEvent(ISubstituteState state, Func<ICall, object[]> getEventArguments) { return new Route(new ICallHandler[] { new ClearLastCallRouterHandler(state.SubstitutionContext) , new ClearUnusedCallSpecHandler(state) , new RaiseEventHandler(state.EventHandlerRegistry, getEventArguments) , ReturnDefaultForReturnTypeHandler() }); }
public IRoute RaiseEvent(ISubstituteState state, Func <ICall, object?[]> getEventArguments) { return(new Route(new ICallHandler[] { new ClearLastCallRouterHandler(_threadLocalContext) , new ClearUnusedCallSpecHandler(_threadLocalContext.PendingSpecification) , new RaiseEventHandler(state.EventHandlerRegistry, getEventArguments) , 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 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 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 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(state.SubstitutionContext) , new ClearUnusedCallSpecHandler(state) , new CheckReceivedCallsHandler(state.ReceivedCalls, state.CallSpecificationFactory, new ReceivedCallsExceptionThrower(), matchArgs, requiredQuantity) , ReturnDefaultForReturnTypeHandler() })); }
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 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() }); }
public IRoute CallQuery(ISubstituteState state) { return(new Route(new ICallHandler[] { new ClearUnusedCallSpecHandler(_threadLocalContext.PendingSpecification) , new AddCallToQueryResultHandler(_threadLocalContext) , new ReturnAutoValue(AutoValueBehaviour.UseValueForSubsequentCalls, state.AutoValueProviders, state.AutoValuesCallResults, _callSpecificationFactory) , ReturnDefaultForReturnTypeHandler() })); }
public override void Context() { _callStack = mock <ICallStack>(); _callResults = mock <ICallResults>(); _routeArguments = new object[] { 2 }; _substituteState = mock <ISubstituteState>(); _substituteState.stub(x => x.FindInstanceFor(typeof(ICallStack), _routeArguments)).Return(_callStack); _substituteState.stub(x => x.FindInstanceFor(typeof(ICallResults), _routeArguments)).Return(_callResults); _substituteState.stub(x => x.FindInstanceFor(typeof(int), _routeArguments)).Return(_routeArguments[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() }); }
public IRoute RecordCallSpecification(ISubstituteState state) { return(new Route(new ICallHandler[] { new RecordCallSpecificationHandler(_threadLocalContext.PendingSpecification, _callSpecificationFactory, state.CallActions) , new PropertySetterHandler(_propertyHelper, state.ConfigureCall) , new ReturnAutoValue(AutoValueBehaviour.UseValueForSubsequentCalls, state.AutoValueProviders, state.AutoValuesCallResults, _callSpecificationFactory) , new ReturnFromAndConfigureDynamicCall(state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() })); }
public IRoute RecordCallSpecification(ISubstituteState state) { return(new Route(new ICallHandler[] { new RecordCallSpecificationHandler(state.PendingSpecification, state.CallSpecificationFactory, state.CallActions) , new PropertySetterHandler(new PropertyHelper(), state.ConfigureCall) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnAutoValueForThisAndSubsequentCallsHandler(state.AutoValueProviders, state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() })); }
public IRoute RecordCallSpecification(ISubstituteState state) { return(new Route(new ICallHandler[] { new RecordCallSpecificationHandler(state.PendingSpecification, state.CallSpecificationFactory, state.CallActions) , new PropertySetterHandler(new PropertyHelper(new CallFactory(), new ArgumentSpecificationCompatibilityTester(new DefaultChecker(new DefaultForType()))), state.ConfigureCall) , new ReturnAutoValue(AutoValueBehaviour.UseValueForSubsequentCalls, state.AutoValueProviders, state.AutoValuesCallResults, state.CallSpecificationFactory) , new ReturnFromAndConfigureDynamicCall(state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() })); }
public IRoute RecordCallSpecification(ISubstituteState state) { return new Route(new ICallHandler[] { new RecordCallSpecificationHandler(state.PendingSpecification, state.CallSpecificationFactory, state.CallActions) , new PropertySetterHandler(new PropertyHelper(), state.ConfigureCall) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnAutoValueForThisAndSubsequentCallsHandler(state.AutoValueProviders, state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() }); }
public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory) { _substituteState = substituteState; _context = context; _routeFactory = routeFactory; _receivedCalls = substituteState.ReceivedCalls; ConfigureCall = substituteState.ConfigureCall; UseDefaultRouteForNextCall(); }
public NoSetupCallbackHandler(ISubstituteState state, Action action) { if (state == null) throw new ArgumentNullException("state"); if (action == null) throw new ArgumentNullException("action"); this.state = state; this.action = action; }
private object GetParameter(Type type, ISubstituteState substituteState, object[] routeArguments) { var parameter = substituteState.FindInstanceFor(type, routeArguments); if (parameter == null) { throw new SubstituteException("Cannot create handler. Cannot find an instance of " + type.FullName); } return(parameter); }
public IRoute RecordCallSpecification(ISubstituteState state) { // Don't care about concurrency - routes are immutable and in worst case we'll simply create a few ones. if (_recordCallSpecificationCache.State != state) { _recordCallSpecificationCache = new CachedRoute(_factory.RecordCallSpecification(state), state); } return(_recordCallSpecificationCache.Route); }
public IRoute CallQuery(ISubstituteState state) { return(new Route(new ICallHandler[] { new ClearUnusedCallSpecHandler(state) , new AddCallToQueryResultHandler(state.SubstitutionContext, state.CallSpecificationFactory) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnAutoValueForThisAndSubsequentCallsHandler(state.AutoValueProviders, state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() })); }
public IRoute CallQuery(ISubstituteState state) { return new Route(new ICallHandler[] { new ClearUnusedCallSpecHandler(state) , new AddCallToQueryResultHandler(state.SubstitutionContext, state.CallSpecificationFactory) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnAutoValueForThisAndSubsequentCallsHandler(state.AutoValueProviders, state.ConfigureCall) , 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() })); }
IRoute IRouteFactory.CallQuery(ISubstituteState state) { return new Route(new ICallHandler[] { new ClearUnusedCallSpecHandler(state), new AddCallToQueryResultHandler(state.SubstitutionContext, state.CallSpecificationFactory), // new ReturnConfiguredResultHandler(state.CallResults), <- handler incompatible with FluentArgumentSpecification new ReturnAutoValue(AutoValueBehaviour.UseValueForSubsequentCalls, state.AutoValueProviders, state.ConfigureCall), new ReturnDefaultForReturnTypeHandler(new DefaultForType()) }); }
public override void Context() { _substituteState = mock <ISubstituteState>(); _callHandlers = new[] { mock <ICallHandler>(), mock <ICallHandler>() }; _routeArguments = new[] { new object(), new object() }; _callHandlerFactory = mock <ICallHandlerFactory>(); _callHandlerFactory.stub(x => x.CreateCallHandler(SampleRouteDefinition.Handlers[0], _substituteState, _routeArguments)).Return(_callHandlers[0]); _callHandlerFactory.stub(x => x.CreateCallHandler(SampleRouteDefinition.Handlers[1], _substituteState, _routeArguments)).Return(_callHandlers[1]); temporarilyChange(() => RouteFactory.ConstructRoute).to(x => new FakeRoute(x)); }
public IRoute RecordReplay(ISubstituteState state) { return(new Route(RouteType.RecordReplay, new ICallHandler[] { new ClearUnusedCallSpecHandler(state) , new RecordCallHandler(state.CallStack, state.SequenceNumberGenerator) , new EventSubscriptionHandler(state.EventHandlerRegistry) , new PropertySetterHandler(new PropertyHelper(), state.ConfigureCall) , new DoActionsCallHandler(state.CallActions) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnAutoValueForThisAndSubsequentCallsHandler(state.AutoValueProviders, state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() })); }
public IRoute RecordReplay(ISubstituteState state) { return new Route(RouteType.RecordReplay, new ICallHandler[] { new ClearUnusedCallSpecHandler(state) , new RecordCallHandler(state.CallStack, state.SequenceNumberGenerator) , new EventSubscriptionHandler(state.EventHandlerRegistry) , new PropertySetterHandler(new PropertyHelper(), state.ConfigureCall) , new DoActionsCallHandler(state.CallActions) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnAutoValueForThisAndSubsequentCallsHandler(state.AutoValueProviders, state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() }); }
public NoSetupCallbackHandler(ISubstituteState state, Action action) { if (state == null) { throw new ArgumentNullException("state"); } if (action == null) { throw new ArgumentNullException("action"); } this.state = state; this.action = action; }
public IRoute RecordReplay(ISubstituteState state) { return(new Route(RouteType.RecordReplay, new ICallHandler[] { new ClearUnusedCallSpecHandler(state) , new RecordCallHandler(state.CallStack, state.SequenceNumberGenerator) , new EventSubscriptionHandler(state.EventHandlerRegistry) , new PropertySetterHandler(new PropertyHelper(), state.ConfigureCall) , new DoActionsCallHandler(state.CallActions) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnResultForTypeHandler(state.ResultsForType) , new ReturnFromBaseIfRequired(state.SubstituteConfig, state.CallBaseExclusions) , new ReturnAutoValue(AutoValueBehaviour.UseValueForSubsequentCalls, state.AutoValueProviders, state.ConfigureCall) , new ReturnFromAndConfigureDynamicCall(state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() })); }
public IRoute RecordReplay(ISubstituteState state) { return new Route(RouteType.RecordReplay, new ICallHandler[] { new ClearUnusedCallSpecHandler(state) , new RecordCallHandler(state.CallStack, state.SequenceNumberGenerator) , new EventSubscriptionHandler(state.EventHandlerRegistry) , new PropertySetterHandler(new PropertyHelper(), state.ConfigureCall) , new DoActionsCallHandler(state.CallActions) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnResultForTypeHandler(state.ResultsForType) , new ReturnFromBaseIfRequired(state.SubstituteConfig, state.CallBaseExclusions) , new ReturnAutoValue(AutoValueBehaviour.UseValueForSubsequentCalls, state.AutoValueProviders, state.ConfigureCall) , new ReturnFromAndConfigureDynamicCall(state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() }); }
public override void Context() { _context = mock <ISubstitutionContext>(); _call = mock <ICall>(); _state = mock <ISubstituteState>(); _receivedCalls = mock <IReceivedCalls>(); ConfigureCall = mock <IConfigureCall>(); _routeFactory = mock <IRouteFactory>(); _state.stub(x => x.ReceivedCalls).Return(_receivedCalls); _state.stub(x => x.ConfigureCall).Return(ConfigureCall); var recordReplayRoute = CreateRouteThatReturns(_returnValueFromRecordReplayRoute); recordReplayRoute.stub(x => x.IsRecordReplayRoute).Return(true); _routeFactory.stub(x => x.RecordReplay(_state)).Return(recordReplayRoute); }
public IRoute RecordReplay(ISubstituteState state) { return(new Route(new ICallHandler[] { new TrackLastCallHandler(_threadLocalContext.PendingSpecification) , new RecordCallHandler(state.ReceivedCalls, _sequenceNumberGenerator) , new EventSubscriptionHandler(state.EventHandlerRegistry) , new PropertySetterHandler(_propertyHelper, state.ConfigureCall) , new DoActionsCallHandler(state.CallActions) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnResultForTypeHandler(state.ResultsForType) , new ReturnFromBaseIfRequired(state.CallBaseConfiguration) , new ReturnFromCustomHandlers(state.CustomHandlers) , new ReturnAutoValue(AutoValueBehaviour.UseValueForSubsequentCalls, state.AutoValueProviders, state.AutoValuesCallResults, _callSpecificationFactory) , new ReturnFromAndConfigureDynamicCall(state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() })); }
public IRoute RecordReplay(ISubstituteState state) { return(new Route(RouteType.RecordReplay, new ICallHandler[] { new ClearUnusedCallSpecHandler(state.PendingSpecification) , new TrackLastCallHandler(state.PendingSpecification) , new RecordCallHandler(state.CallCollection, state.SequenceNumberGenerator) , new EventSubscriptionHandler(state.EventHandlerRegistry) , new PropertySetterHandler(new PropertyHelper(new CallFactory(), new ArgumentSpecificationCompatibilityTester(new DefaultChecker(new DefaultForType()))), state.ConfigureCall) , new DoActionsCallHandler(state.CallActions) , new ReturnConfiguredResultHandler(state.CallResults) , new ReturnResultForTypeHandler(state.ResultsForType) , new ReturnFromBaseIfRequired(state.SubstituteConfig, state.CallBaseExclusions) , new ReturnFromCustomHandlers(state.CustomHandlers) , new ReturnAutoValue(AutoValueBehaviour.UseValueForSubsequentCalls, state.AutoValueProviders, state.AutoValuesCallResults, state.CallSpecificationFactory) , new ReturnFromAndConfigureDynamicCall(state.ConfigureCall) , ReturnDefaultForReturnTypeHandler() })); }
public static ICallSpecificationFactory GetCallSpecificationFactory(ISubstituteState substituteState, ISubstitutionContext substitutionContext) => CallSpecificationFactoryResolver.Invoke(substituteState, substitutionContext);
public CustomHandlers(ISubstituteState substituteState) { _substituteState = substituteState; }
public ClearUnusedCallSpecHandler(ISubstituteState state) { _state = state; }
public CachedRoute(IRoute route, ISubstituteState state) { Route = route; State = state; }