public async Task InvokeMessageHandlersForEventMessageAsync_ShouldInvokeAllRegisteredPerformanceMonitorsWithAppropriateErrorInfoWhenAHandlerBlows()
        {
            var performanceMonitor = new Mock <IEventStreamSubscriberPerformanceMonitor>();


            var expectedException = new InvalidTimeZoneException("Summat");
            var handler           = new Mock <IHandleEventsOf <object> >();

            handler.Setup(x => x.Handle(It.IsAny <object>())).Throws(expectedException);

            var called = false;

            performanceMonitor.Setup(x => x.Accept(StreamName, typeof(object).FullName, EventDate, 1, It.IsAny <IEnumerable <KeyValuePair <Type, Exception> > >())).Callback <string, string, DateTime, int, IEnumerable <KeyValuePair <Type, Exception> > >(
                (stream, type, createdDate, handlerCount, exceptions) =>
            {
                called = true;
                exceptions.Should().BeEquivalentTo(new[] { new KeyValuePair <Type, Exception>(handler.Object.GetType(), expectedException) });
            });

            var builder = new EventStreamSubscriberSettingsBuilder(_eventStoreHttpConnectionMock.Object, _eventHandlerResolverMock.Object, _streamPositionRepositoryMock.Object).WithCustomEventTypeResolver(_eventTypeResolverMock.Object).AddPerformanceMonitor(performanceMonitor.Object);

            _subscriber = (EventStreamSubscriber)EventStreamSubscriber.Create(builder);

            await _subscriber.InvokeMessageHandlersForEventMessageAsync(StreamName, typeof(object), new[] { handler.Object }, new object(), EventInfo);

            called.Should().BeTrue();
        }
        public async Task PollAsync_WhenNoEventHandlersFound_ShouldInvokeAllRegisteredPerformanceMonitorsWithAppropriateInfo()
        {
            var performanceMonitor = new Mock <IEventStreamSubscriberPerformanceMonitor>();

            var streamSliceResult = new StreamEventsSlice
            {
                Entries = new List <BasicEventInfo> {
                    new BasicEventInfo {
                        Title = "1@Stream", EventType = "SomeType", Updated = EventDate
                    }
                }
            };

            var count = 0;

            _eventStoreHttpConnectionMock.Setup(x => x.ReadStreamEventsForwardAsync(StreamName, It.IsAny <int>(), It.IsAny <int>(), It.IsAny <TimeSpan?>())).Returns(async() => streamSliceResult).Callback(
                () =>
            {
                if (count++ == 2)
                {
                    streamSliceResult.Entries.Clear();
                }
            });

            var builder = new EventStreamSubscriberSettingsBuilder(_eventStoreHttpConnectionMock.Object, _eventHandlerResolverMock.Object, _streamPositionRepositoryMock.Object).WithCustomEventTypeResolver(_eventTypeResolverMock.Object).AddPerformanceMonitor(performanceMonitor.Object);

            _subscriber = (EventStreamSubscriber)EventStreamSubscriber.Create(builder);

            await _subscriber.PollAsync(StreamName, SubscriberId);

            performanceMonitor.Verify(x => x.Accept(StreamName, "SomeType", EventDate, 0, It.IsAny <IEnumerable <KeyValuePair <Type, Exception> > >()));
        }
        public void SubscribeTo_ShouldInvokeSubscriptionManagerWithDefaultPeriodIfNoneIsPassed()
        {
            var builder = new EventStreamSubscriberSettingsBuilder(_eventStoreHttpConnectionMock.Object, _eventHandlerResolverMock.Object, _streamPositionRepositoryMock.Object).WithDefaultPollingInterval(TimeSpan.FromDays(456)).WithCustomEventTypeResolver(_eventTypeResolverMock.Object).WithCustomSubscriptionTimerManager(_subscriptionTimerManagerMock.Object);

            _subscriber = (EventStreamSubscriber)EventStreamSubscriber.Create(builder);
            _subscriber.SubscribeTo(It.IsAny <string>(), It.IsAny <string>());
            _subscriptionTimerManagerMock.Verify(x => x.Add(It.IsAny <string>(), It.IsAny <string>(), TimeSpan.FromDays(456), It.IsAny <Func <Task> >(), It.IsAny <Action>()));
        }
        public void Setup()
        {
            _connectionMock               = new Mock <IEventStoreHttpConnection>();
            _eventHandlerResolverMock     = new Mock <IEventHandlerResolver>();
            _streamPositionRepositoryMock = new Mock <IStreamPositionRepository>();
            _eventTypeResolverMock        = new Mock <IEventTypeResolver>();

            _builder = new EventStreamSubscriberSettingsBuilder(_connectionMock.Object, _eventHandlerResolverMock.Object, _streamPositionRepositoryMock.Object).WithCustomEventTypeResolver(_eventTypeResolverMock.Object);
        }
        public async Task InvokeMessageHandlersForEventMessageAsync_ShouldInvokeAllRegisteredPerformanceMonitorsWithAppropriateInfo()
        {
            var performanceMonitor1 = new Mock <IEventStreamSubscriberPerformanceMonitor>();
            var performanceMonitor2 = new Mock <IEventStreamSubscriberPerformanceMonitor>();

            var handlers = new[] { Mock.Of <IHandleEventsOf <object> >(), Mock.Of <IHandleEventsOf <object> >() };

            var builder = new EventStreamSubscriberSettingsBuilder(_eventStoreHttpConnectionMock.Object, _eventHandlerResolverMock.Object, _streamPositionRepositoryMock.Object).WithCustomEventTypeResolver(_eventTypeResolverMock.Object).AddPerformanceMonitor(performanceMonitor1.Object, performanceMonitor2.Object);

            _subscriber = (EventStreamSubscriber)EventStreamSubscriber.Create(builder);

            await _subscriber.InvokeMessageHandlersForEventMessageAsync(StreamName, typeof(object), handlers, new object(), EventInfo);

            performanceMonitor1.Verify(x => x.Accept(StreamName, typeof(object).FullName, EventDate, 2, It.IsAny <IEnumerable <KeyValuePair <Type, Exception> > >()));
            performanceMonitor2.Verify(x => x.Accept(StreamName, typeof(object).FullName, EventDate, 2, It.IsAny <IEnumerable <KeyValuePair <Type, Exception> > >()));
        }
        public void Setup()
        {
            _eventStoreHttpConnectionMock        = new Mock <IEventStoreHttpConnection>();
            _eventHandlerResolverMock            = new Mock <IEventHandlerResolver>();
            _streamPositionRepositoryMock        = new Mock <IStreamPositionRepository>();
            _subscriptionTimerManagerMock        = new Mock <ISubscriptionTimerManager>();
            _eventTypeResolverMock               = new Mock <IEventTypeResolver>();
            _streamSubscriberIntervalMonitorMock = new Mock <IStreamSubscriberIntervalMonitor>();

            var builder =
                new EventStreamSubscriberSettingsBuilder(_eventStoreHttpConnectionMock.Object,
                                                         _eventHandlerResolverMock.Object, _streamPositionRepositoryMock.Object)
                .WithCustomEventTypeResolver(_eventTypeResolverMock.Object)
                .WithCustomSubscriptionTimerManager(_subscriptionTimerManagerMock.Object)
                .WithCustomEventStreamSubscriberIntervalMonitor(_streamSubscriberIntervalMonitorMock.Object)
                .WithEventNotFoundRetryCountOf(EventNotFoundRetryCount);

            _subscriber = (EventStreamSubscriber)EventStreamSubscriber.Create(builder);
        }