public void EventStoreContext_ConnectToSubscription_ConnectException_ErrorThrown()
        {
            EventStorePersistentSubscription result = null;

            EventStoreConnectionSettings eventStoreConnectionSettings = EventStoreConnectionSettings.Create(EventStoreContextTestData.ConnectionString);
            Mock <IEventStoreConnection> connection = new Mock <IEventStoreConnection>();

            connection.Setup(c => c.ConnectToPersistentSubscriptionAsync(It.IsAny <String>(), It.IsAny <String>(),
                                                                         It.IsAny <Func <EventStorePersistentSubscriptionBase, ResolvedEvent, Int32?, Task> >(),
                                                                         It.IsAny <Action <EventStorePersistentSubscriptionBase, SubscriptionDropReason, Exception> >(),
                                                                         It.IsAny <UserCredentials>(), It.IsAny <Int32>(), It.IsAny <Boolean>()))
            .Throws(new Exception("Error", new Exception("Some nasty error")));

            Mock <ISerialiser> serialiser = new Mock <ISerialiser>();
            Func <EventStoreConnectionSettings, IEventStoreConnection> connectionResolver = settings =>
            {
                return(connection.Object);
            };

            PaymentCentric.Logging.Logger.Initialise(NullLogger.Instance);

            EventStoreContext context = new EventStoreContext(eventStoreConnectionSettings, connectionResolver, serialiser.Object);

            Should.Throw <Exception>(async() =>
            {
                await context.ConnectToSubscription(EventStoreContextTestData.StreamName,
                                                    EventStoreContextTestData.GroupName,
                                                    EventStoreContextTestData.PersistentSubscriptionId,
                                                    EventStoreContextTestData.BufferSize);
            });
        }
        public async Task EventStoreContext_ConnectToSubscription_ExisitngSubscription_ConnectionMade()
        {
            EventStorePersistentSubscription result = null;

            EventStoreConnectionSettings eventStoreConnectionSettings = EventStoreConnectionSettings.Create(EventStoreContextTestData.ConnectionString);
            Mock <IEventStoreConnection> connection = new Mock <IEventStoreConnection>();

            connection.Setup(c => c.ConnectToPersistentSubscriptionAsync(It.IsAny <String>(), It.IsAny <String>(),
                                                                         It.IsAny <Func <EventStorePersistentSubscriptionBase, ResolvedEvent, Int32?, Task> >(),
                                                                         It.IsAny <Action <EventStorePersistentSubscriptionBase, SubscriptionDropReason, Exception> >(),
                                                                         It.IsAny <UserCredentials>(), It.IsAny <Int32>(), It.IsAny <Boolean>()))
            .ReturnsAsync(result);
            Mock <ISerialiser> serialiser = new Mock <ISerialiser>();

            Func <EventStoreConnectionSettings, IEventStoreConnection> connectionResolver = settings =>
            {
                return(connection.Object);
            };

            PaymentCentric.Logging.Logger.Initialise(NullLogger.Instance);

            EventStoreContext context = new EventStoreContext(eventStoreConnectionSettings, connectionResolver, serialiser.Object);

            await context.ConnectToSubscription(EventStoreContextTestData.StreamName, EventStoreContextTestData.GroupName,
                                                EventStoreContextTestData.PersistentSubscriptionId,
                                                EventStoreContextTestData.BufferSize);

            connection.Verify(x => x.ConnectToPersistentSubscriptionAsync(It.IsAny <String>(), It.IsAny <String>(), It.IsAny <Func <EventStorePersistentSubscriptionBase, ResolvedEvent, Int32?, Task> >(),
                                                                          It.IsAny <Action <EventStorePersistentSubscriptionBase, SubscriptionDropReason, Exception> >(), It.IsAny <UserCredentials>(), It.IsAny <Int32>(), It.IsAny <Boolean>()), Times.Exactly(1));
        }
        public void EventStoreContext_ConnectToSubscription_ConnectException_InvalidData_ErrorThrown(String streamName, String groupName, Boolean validSubscriptionGroupId, Type exceptionType)
        {
            EventStorePersistentSubscription result = null;

            EventStoreConnectionSettings eventStoreConnectionSettings = EventStoreConnectionSettings.Create(EventStoreContextTestData.ConnectionString);
            Mock <IEventStoreConnection> connection = new Mock <IEventStoreConnection>();
            Mock <ISerialiser>           serialiser = new Mock <ISerialiser>();
            Func <EventStoreConnectionSettings, IEventStoreConnection> connectionResolver = settings =>
            {
                return(connection.Object);
            };

            PaymentCentric.Logging.Logger.Initialise(NullLogger.Instance);

            EventStoreContext context = new EventStoreContext(eventStoreConnectionSettings, connectionResolver, serialiser.Object);

            Should.Throw <Exception>(async() =>
            {
                await context.ConnectToSubscription(streamName, groupName, validSubscriptionGroupId ? EventStoreContextTestData.PersistentSubscriptionId : Guid.Empty,
                                                    EventStoreContextTestData.BufferSize);
            });
        }