コード例 #1
0
        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);
            });
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        /// <summary>
        /// Configures the common container.
        /// </summary>
        /// <param name="configurationExpression">The configuration expression.</param>
        private static void ConfigureCommonContainer(ConfigurationExpression configurationExpression)
        {
            String connString     = Program.Configuration.GetValue <String>("EventStoreSettings:ConnectionString");
            String connectionName = Program.Configuration.GetValue <String>("EventStoreSettings:ConnectionName");
            Int32  httpPort       = Program.Configuration.GetValue <Int32>("EventStoreSettings:HttpPort");

            EventStoreConnectionSettings settings = EventStoreConnectionSettings.Create(connString, connectionName, httpPort);

            configurationExpression.For <IEventStoreContext>().Use <EventStoreContext>().Singleton().Ctor <EventStoreConnectionSettings>().Is(settings);

            Func <String, IEventStoreContext> eventStoreContextFunc = (connectionString) =>
            {
                EventStoreConnectionSettings connectionSettings = EventStoreConnectionSettings.Create(connectionString, connectionName, httpPort);

                ExplicitArguments args = new ExplicitArguments().Set(connectionSettings);

                return(Bootstrapper.Container.GetInstance <IEventStoreContext>(args));
            };

            configurationExpression.For <Func <String, IEventStoreContext> >().Use(eventStoreContextFunc);

            Func <EventStoreConnectionSettings, IEventStoreConnection> eventStoreConnectionFunc = (connectionSettings) =>
            {
                return(EventStoreConnection.Create(connectionSettings.ConnectionString));
            };

            configurationExpression.For <Func <EventStoreConnectionSettings, IEventStoreConnection> >().Use(eventStoreConnectionFunc);
        }
 public void EventStoreConnectionSettings_CanBeCreated_InvalidConnectionString_ErrorThrown(String connecttionString)
 {
     Should.Throw <ArgumentException>(() =>
     {
         EventStoreConnectionSettings eventStoreConnectionSettings =
             EventStoreConnectionSettings.Create(connecttionString);
     });
 }
コード例 #5
0
        public CommonRegistry()
        {
            String connString     = Startup.Configuration.GetValue <String>("EventStoreSettings:ConnectionString");
            String connectionName = Startup.Configuration.GetValue <String>("EventStoreSettings:ConnectionName");
            Int32  httpPort       = Startup.Configuration.GetValue <Int32>("EventStoreSettings:HttpPort");

            EventStoreConnectionSettings settings = EventStoreConnectionSettings.Create(connString, connectionName, httpPort);

            this.For <IEventStoreContext>().Use <EventStoreContext>().Singleton().Ctor <EventStoreConnectionSettings>().Is(settings);

            Func <String, IEventStoreContext> eventStoreContextFunc = (connectionString) =>
            {
                EventStoreConnectionSettings connectionSettings = EventStoreConnectionSettings.Create(connectionString, connectionName, httpPort);

                ExplicitArguments args = new ExplicitArguments().Set(connectionSettings);

                return(Startup.Container.GetInstance <IEventStoreContext>(args));
            };

            Func <EventStoreConnectionSettings, IEventStoreConnection> eventStoreConnectionFunc = (connectionSettings) =>
            {
                return(EventStoreConnection.Create(connectionSettings.ConnectionString));
            };

            this.For <IDomainEventHandler>().Use <GolfClubDomainEventHandler>().Named("GolfClub");
            this.For <IDomainEventHandler>().Use <GolfClubMembershipDomainEventHandler>().Named("GolfClubMembership");
            this.For <IDomainEventHandler>().Use <TournamentDomainEventHandler>().Named("Tournament");
            this.For <IDomainEventHandler>().Use <HandicapCalculationDomainEventHandler>().Named("HandicapCalculator");
            this.For <IDomainEventHandler>().Use <ReportingDomainEventHandler>().Named("Reporting");

            Func <String, IDomainEventHandler> domainEventHanderFunc = (name) => Startup.Container.GetInstance <IDomainEventHandler>(name);

            this.For <Func <EventStoreConnectionSettings, IEventStoreConnection> >().Use(eventStoreConnectionFunc);

            this.For <ESLogger.ILogger>().Use <ESLogger.Common.Log.ConsoleLogger>().Singleton();
            this.For <ICommandRouter>().Use <CommandRouter>().Singleton();
            this.For <IAggregateRepository <GolfClubAggregate> >()
            .Use <AggregateRepository <GolfClubAggregate> >().Singleton();
            this.For <IAggregateRepository <GolfClubMembershipAggregate> >()
            .Use <AggregateRepository <GolfClubMembershipAggregate> >().Singleton();
            this.For <IAggregateRepository <TournamentAggregate> >()
            .Use <AggregateRepository <TournamentAggregate> >().Singleton();
            this.For <IAggregateRepository <PlayerAggregate> >()
            .Use <AggregateRepository <PlayerAggregate> >().Singleton();
            this.For <IAggregateRepository <HandicapCalculationProcessAggregate> >()
            .Use <AggregateRepository <HandicapCalculationProcessAggregate> >().Singleton();

            this.For <IHandicapAdjustmentCalculatorService>().Use <HandicapAdjustmentCalculatorService>();
            //this.For<IManagmentAPIManager>().Use<ManagementAPIManager>().AlwaysUnique().Singleton();
            this.RegisterType <IManagmentAPIManager, ManagementAPIManager>().Singleton();
            this.For <IReportingManager>().Use <ReportingManager>().Singleton();
            this.For <ISecurityService>().Use <SecurityService>().Singleton();
            this.For <IGolfClubMembershipApplicationService>().Use <GolfClubMembershipApplicationService>().Singleton();
            this.For <ITournamentApplicationService>().Use <TournamentApplicationService>().Singleton();

            this.For <IHandicapCalculationProcessorService>().Use <HandicapCalculationProcessorService>().Transient();
        }
コード例 #6
0
        private EventStoreConnectionSettings GetConnectionSettings()
        {
            var connectionSettings = new EventStoreConnectionSettings();

            connectionSettings.TcpEndpoint(appSettings.GetString("ServiceStack.Plugins.EventStore.TcpEndPoint"));
            connectionSettings.HttpEndpoint(appSettings.GetString("ServiceStack.Plugins.EventStore.HttpEndPoint"));
            connectionSettings.UserName(appSettings.GetString("ServiceStack.Plugins.EventStore.UserName"));
            connectionSettings.Password(appSettings.GetString("ServiceStack.Plugins.EventStore.Password"));

            return(connectionSettings);
        }
        public void EventStoreConnectionSettings_CanBeCreated_ValidConnectionString_SetHttpPort_IsCreated()
        {
            EventStoreConnectionSettings eventStoreConnectionSettings = EventStoreConnectionSettings.Create(EventStoreConnectionSettingsTestData.ConnectionString, httpPort: EventStoreConnectionSettingsTestData.HttpPort);

            eventStoreConnectionSettings.ShouldNotBeNull();
            eventStoreConnectionSettings.ConnectionString.ShouldBe(EventStoreConnectionSettingsTestData.ConnectionString);
            eventStoreConnectionSettings.ConnectionName.ShouldBeNull();
            eventStoreConnectionSettings.HttpPort.ShouldBe(EventStoreConnectionSettingsTestData.HttpPort);
            eventStoreConnectionSettings.IPAddress.ShouldBe(EventStoreConnectionSettingsTestData.IPAddress);
            eventStoreConnectionSettings.Password.ShouldBe(EventStoreConnectionSettingsTestData.Password);
            eventStoreConnectionSettings.TcpPort.ShouldBe(EventStoreConnectionSettingsTestData.TcpPort);
            eventStoreConnectionSettings.UserName.ShouldBe(EventStoreConnectionSettingsTestData.UserName);
        }
コード例 #8
0
        public override void Configure(Container container)
        {
            var connection = new EventStoreConnectionSettings()
                             .UserName("admin")
                             .Password("changeit")
                             .TcpEndpoint("localhost:1113")
                             .HttpEndpoint("localhost:2113");


            LogManager.LogFactory = new ConsoleLogFactory();

            Plugins.Add(new EventStoreFeature(connection, typeof(TestAppHost).Assembly));
            Plugins.Add(new MetadataFeature());
        }
コード例 #9
0
        public void EventStoreContext_CanBeCreated_IsCreated()
        {
            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);
            };

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

            context.ShouldNotBeNull();
        }
コード例 #10
0
        public void EventStoreContext_CanBeCreated_NullConnectionSettings_ErrorThrown()
        {
            EventStoreConnectionSettings eventStoreConnectionSettings = null;
            Mock <IEventStoreConnection> connection = new Mock <IEventStoreConnection>();
            Mock <ISerialiser>           serialiser = new Mock <ISerialiser>();
            Func <EventStoreConnectionSettings, IEventStoreConnection> connectionResolver = settings =>
            {
                return(connection.Object);
            };

            Should.Throw <ArgumentNullException>(() =>
            {
                EventStoreContext context = new EventStoreContext(eventStoreConnectionSettings, connectionResolver, serialiser.Object);
            });
        }
コード例 #11
0
        public async Task EventStoreContext_CreatePersistentSubscriptionFromPosition_InvalidData_ErrorThrown(String streamName, String groupName, Type exceptionType)
        {
            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(async() => { await context.CreatePersistentSubscriptionFromPosition(streamName, groupName, EventStoreContextTestData.StartPosition); }, exceptionType);
        }
コード例 #12
0
        /// <summary>
        /// Starts the event store projections.
        /// </summary>
        private static async Task StartEventStoreProjections()
        {
            // TODO: Refactor
            // This method is a brutal way of getting projections to be run when the API starts up
            // This needs refactored into a more pleasant function
            String connString     = Startup.Configuration.GetValue <String>("EventStoreSettings:ConnectionString");
            String connectionName = Startup.Configuration.GetValue <String>("EventStoreSettings:ConnectionName");
            Int32  httpPort       = Startup.Configuration.GetValue <Int32>("EventStoreSettings:HttpPort");

            EventStoreConnectionSettings settings = EventStoreConnectionSettings.Create(connString, connectionName, httpPort);

            // Do continuous first
            String continuousProjectionsFolder = ConfigurationReader.GetValue("EventStoreSettings", "ContinuousProjectionsFolder");

            String[] files = Directory.GetFiles(continuousProjectionsFolder, "*.js");

            // TODO: Improve this later to get status of projection before trying to create
            //foreach (String file in files)
            //{
            //    String withoutExtension = Path.GetFileNameWithoutExtension(file);
            //    String projectionBody = File.ReadAllText(file);
            //    Boolean emitEnabled = continuousProjectionsFolder.ToLower().Contains("emitenabled");

            //    await Retry.For(async () =>
            //                    {
            //                        DnsEndPoint d = new DnsEndPoint(settings.IpAddress, settings.HttpPort);

            //                        ProjectionsManager projectionsManager = new ProjectionsManager(new ConsoleLogger(), d, TimeSpan.FromSeconds(5));

            //                        UserCredentials userCredentials = new UserCredentials(settings.UserName, settings.Password);

            //                        String projectionStatus = await projectionsManager.GetStatusAsync(withoutExtension, userCredentials);

            //                        await projectionsManager.CreateContinuousAsync(withoutExtension, projectionBody, userCredentials);
            //                        Logger.LogInformation("After CreateContinuousAsync");
            //                        if (emitEnabled)
            //                        {
            //                            await projectionsManager.AbortAsync(withoutExtension, userCredentials);
            //                            await projectionsManager.UpdateQueryAsync(withoutExtension, projectionBody, emitEnabled, userCredentials);
            //                            await projectionsManager.EnableAsync(withoutExtension, userCredentials);
            //                        }
            //                    });
            //}
        }
コード例 #13
0
        public override void Configure(Container container)
        {
            //when using a ReadModelSubscription we do not pass in the stream name
            //since it subscribes to all streams (the $all projection in event store)
            var subscriptionSettings = new SubscriptionSettings()
                                       .SubscribeToStreams(s => s.Add(new ReadModelSubscription()
                                                                      .WithStorage(new ReadModelStorage(StorageType.Redis, "localhost:6379"))));

            //these three settings are the minimum configuration required to
            //set up a connection to EventStore
            var connectionSettings = new EventStoreConnectionSettings()
                                     .UserName("admin")
                                     .Password("changeit")
                                     .TcpEndpoint("localhost:1113");

            //we instantiate the plugin using the connection and subscription data as well as a
            //parameter array of the assemblies where the plugin can find the CLR event types
            Plugins.Add(new EventStoreFeature(connectionSettings, subscriptionSettings, typeof(TestAppHost).Assembly));
        }
コード例 #14
0
        public async Task EventStoreContext_DeletePersistentSubscription_SubscriptionDeleted()
        {
            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);

            await context.DeletePersistentSubscription(EventStoreContextTestData.StreamName,
                                                       EventStoreContextTestData.GroupName);

            connection.Verify(x => x.DeletePersistentSubscriptionAsync(EventStoreContextTestData.StreamName, EventStoreContextTestData.GroupName, It.IsAny <UserCredentials>()));
        }
コード例 #15
0
        public async Task EventStoreContext_InsertEvents_EventsInserted()
        {
            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);

            await context.InsertEvents(EventStoreContextTestData.StreamName, EventStoreContextTestData.ExpectedVersion,
                                       EventStoreContextTestData.DomainEvents);

            connection.Verify(x => x.AppendToStreamAsync(EventStoreContextTestData.StreamName, EventStoreContextTestData.ExpectedVersion,
                                                         It.IsAny <List <EventData> >(), It.IsAny <UserCredentials>()));
        }
コード例 #16
0
        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);
            });
        }