Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 public CallRouter(ISubstituteState substituteState, IThreadLocalContext threadContext, IRouteFactory routeFactory, bool canConfigureBaseCalls)
 {
     _substituteState       = substituteState;
     _threadContext         = threadContext;
     _routeFactory          = routeFactory;
     _canConfigureBaseCalls = canConfigureBaseCalls;
 }
Exemplo n.º 3
0
        public CallRouter(ISubstituteState substituteState, IThreadLocalContext threadContext, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _threadContext   = threadContext;
            _routeFactory    = routeFactory;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _context         = context;
            _routeFactory    = routeFactory;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 6
0
        public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _context = context;
            _routeFactory = routeFactory;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 7
0
 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()
     });
 }
Exemplo n.º 8
0
 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()
     }));
 }
Exemplo n.º 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()
     });
 }
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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()
     });
 }
Exemplo n.º 16
0
 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()
     }));
 }
Exemplo n.º 17
0
 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]);
 }
Exemplo n.º 18
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()
     });
 }
Exemplo n.º 19
0
 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()
     }));
 }
Exemplo n.º 20
0
 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()
     }));
 }
Exemplo n.º 21
0
 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()
     }));
 }
Exemplo n.º 22
0
 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()
     });
 }
Exemplo n.º 23
0
        public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _context = context;
            _routeFactory = routeFactory;
            _receivedCalls = substituteState.ReceivedCalls;
            ConfigureCall = substituteState.ConfigureCall;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 24
0
        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;
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
 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()
     }));
 }
Exemplo n.º 28
0
 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()
     });
 }
Exemplo n.º 29
0
        public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _context         = context;
            _routeFactory    = routeFactory;
            _receivedCalls   = substituteState.ReceivedCalls;
            ConfigureCall    = substituteState.ConfigureCall;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 30
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()
     }));
 }
 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())
     });
 }
Exemplo n.º 32
0
            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));
            }
Exemplo n.º 33
0
 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()
     }));
 }
Exemplo n.º 34
0
 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()
     });
 }
Exemplo n.º 35
0
        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;
        }
Exemplo n.º 36
0
 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()
     }));
 }
Exemplo n.º 37
0
 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);
            }
Exemplo n.º 39
0
 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()
     }));
 }
Exemplo n.º 40
0
 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()
     }));
 }
Exemplo n.º 41
0
 public static ICallSpecificationFactory GetCallSpecificationFactory(ISubstituteState substituteState, ISubstitutionContext substitutionContext) =>
 CallSpecificationFactoryResolver.Invoke(substituteState, substitutionContext);
Exemplo n.º 42
0
 public CustomHandlers(ISubstituteState substituteState)
 {
     _substituteState = substituteState;
 }
 public ClearUnusedCallSpecHandler(ISubstituteState state)
 {
     _state = state;
 }
Exemplo n.º 44
0
 public CachedRoute(IRoute route, ISubstituteState state)
 {
     Route = route;
     State = state;
 }
Exemplo n.º 45
0
 public CustomHandlers(ISubstituteState substituteState)
 {
     _substituteState = substituteState;
 }