public void setup()
        {
            _bus = new InMemoryBus("bus");
            _listEventsHandler = new TestHandler <ClientMessage.ReadStreamEventsBackward>();
            _bus.Subscribe(_listEventsHandler);
            _readDispatcher = new RequestResponseDispatcher
                              <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted>(
                _bus, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_bus));
            _writeDispatcher = new RequestResponseDispatcher <ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted>(
                _bus, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_bus));
            _subscriptionDispatcher =
                new PublishSubscribeDispatcher
                <ReaderSubscriptionManagement.Subscribe,
                 ReaderSubscriptionManagement.ReaderSubscriptionManagementMessage, EventReaderSubscriptionMessage>
                    (_bus, v => v.SubscriptionId, v => v.SubscriptionId);
            _bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CommittedEventReceived>());
            _bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CheckpointSuggested>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.EofReached>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ProgressChanged>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.NotAuthorized>());
            _bus.Subscribe(_readDispatcher);
            _bus.Subscribe(_writeDispatcher);
            IProjectionStateHandler projectionStateHandler = new FakeProjectionStateHandler();

            _projectionConfig = new ProjectionConfig(null, 5, 10, 1000, 250, true, true, false, false);
            _coreProjection   = CoreProjection.CreateAndPrepare(
                "projection", new ProjectionVersion(1, 0, 0), Guid.NewGuid(), _bus, projectionStateHandler, _projectionConfig, _readDispatcher,
                _writeDispatcher, _subscriptionDispatcher, null, new RealTimeProvider());
            _coreProjection.Start();
        }
        public void a_null_publisher_throws_exception()
        {
            IProjectionStateHandler projectionStateHandler = new FakeProjectionStateHandler();

            CoreProjection.CreateAndPrepare("projection", new ProjectionVersion(1, 0, 0), Guid.NewGuid(), null, projectionStateHandler, _defaultProjectionConfig,
                                            _readDispatcher, _writeDispatcher, _subscriptionDispatcher, null, new RealTimeProvider());
        }
        public void setup()
        {
            _subscribeProjectionHandler = new TestHandler <ReaderSubscriptionManagement.Subscribe>();
            _writeEventHandler          = new TestHandler <ClientMessage.WriteEvents>();
            _bus.Subscribe(_subscribeProjectionHandler);
            _bus.Subscribe(_writeEventHandler);


            _stateHandler = _stateHandler
                            ?? new FakeProjectionStateHandler(configureBuilder: _configureBuilderByQuerySource);
            _firstWriteCorrelationId = Guid.NewGuid();
            _projectionCorrelationId = Guid.NewGuid();
            _projectionConfig        = new ProjectionConfig(null,
                                                            _checkpointHandledThreshold, _checkpointUnhandledBytesThreshold, 1000, 250, true, true,
                                                            _createTempStreams, _stopOnEof);
            _coreProjection = CoreProjection.CreateAndPrepare(
                "projection", _version, _projectionCorrelationId, _bus, _stateHandler, _projectionConfig, _readDispatcher,
                _writeDispatcher, _subscriptionDispatcher, null, _timeProvider);
            _bus.Subscribe <CoreProjectionProcessingMessage.CheckpointCompleted>(_coreProjection);
            _bus.Subscribe <CoreProjectionProcessingMessage.CheckpointLoaded>(_coreProjection);
            _bus.Subscribe <CoreProjectionProcessingMessage.PrerecordedEventsLoaded>(_coreProjection);
            _bus.Subscribe <CoreProjectionProcessingMessage.RestartRequested>(_coreProjection);
            _bus.Subscribe <CoreProjectionProcessingMessage.Failed>(_coreProjection);
            _bus.Subscribe <EventReaderSubscriptionMessage.CommittedEventReceived>(_coreProjection);
            _bus.Subscribe <EventReaderSubscriptionMessage.CheckpointSuggested>(_coreProjection);
            _bus.Subscribe <EventReaderSubscriptionMessage.EofReached>(_coreProjection);
            _bus.Subscribe <EventReaderSubscriptionMessage.ProgressChanged>(_coreProjection);
            _bus.Subscribe <EventReaderSubscriptionMessage.NotAuthorized>(_coreProjection);
            _bus.Subscribe(new AdHocHandler <ProjectionCoreServiceMessage.CoreTick>(tick => tick.Action()));
            _bus.Subscribe(new AdHocHandler <ReaderCoreServiceMessage.ReaderTick>(tick => tick.Action()));
            PreWhen();
            When();
        }
        public void a_zero_checkpoint_handled_threshold_throws_argument_out_of_range_exception()
        {
            IProjectionStateHandler projectionStateHandler = new FakeProjectionStateHandler();

            CoreProjection.CreateAndPrepare("projection", new ProjectionVersion(1, 0, 0), Guid.NewGuid(), new FakePublisher(), projectionStateHandler,
                                            new ProjectionConfig(null, 0, 10, 1000, 250, true, true, false, false), _readDispatcher,
                                            _writeDispatcher, _subscriptionDispatcher, null, new RealTimeProvider());
        }