public void SaveEventsTest() { var aggregateRootId = Guid.NewGuid(); var employee = new Employee { Id = aggregateRootId }; var event1 = new NameChangedEvent("daxnet"); var event2 = new TitleChangedEvent("title"); var event3 = new RegisteredEvent(); event1.AttachTo(employee); event2.AttachTo(employee); event3.AttachTo(employee); var storeConfig = new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()); var payloadSerializer = new ObjectJsonSerializer(); var store = new PostgreSqlEventStore(storeConfig, payloadSerializer); store.Save(new List <DomainEvent> { event1, event2, event3 }); }
public void OverriddenFieldNameTest2() { var config = new AdoNetEventStoreConfiguration("conn", new KeyValuePair <Expression <Func <EventDescriptor, object> >, string>(x => x.EventClrType, "CLRTYPE")); Assert.Equal("CLRTYPE", config.GetFieldName(x => x.EventClrType)); Assert.Equal("EVENTPAYLOAD", config.GetFieldName(x => x.EventPayload)); }
public void LoadEventsTest() { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); var event1 = new NameChangedEvent("daxnet"); var event2 = new TitleChangedEvent("title"); var event3 = new RegisteredEvent(); event1.AttachTo(employee); event2.AttachTo(employee); event3.AttachTo(employee); var storeConfig = new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()); var payloadSerializer = new ObjectJsonSerializer(); var store = new PostgreSqlEventStore(storeConfig, payloadSerializer); store.Save(new List <DomainEvent> { event1, event2, event3 }); var events = store.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId); Assert.Equal(3, events.Count()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Reads the host machine which runs the RabbitMQ. var rabbitHost = this.Configuration["rabbit:host"]; // Reads the RabbitMQ exchange setting. var rabbitExchangeName = this.Configuration["rabbit:exchange"]; // Reads the name of the event queue. var rabbitEventQueueName = this.Configuration["rabbit:eventQueue"]; // Reads the name of the command queue. var rabbitCommandQueueName = this.Configuration["rabbit:commandQueue"]; // Reads connection string of the event store database. var eventStoreConnectionString = this.Configuration["mssql:event.db"]; // Reads connection string of the query database. var queryDatabaseConnectionString = this.Configuration["mssql:query.db"]; // Event/Command subscribers/publishers var connectionFactory = new ConnectionFactory { HostName = rabbitHost }; var messageSerializer = new MessageJsonSerializer(); var messageHandlerExecutionContext = new ServiceProviderMessageHandlerExecutionContext(services, x => x.BuildServiceProvider()); var eventSubscriber = new RabbitEventBus(connectionFactory, messageSerializer, messageHandlerExecutionContext, rabbitExchangeName, ExchangeType.Topic, rabbitEventQueueName); eventSubscriber.Subscribe <AccountCreatedEvent, AccountCreatedEventHandler>(); eventSubscriber.Subscribe <TextContentChangedEvent, TextContentChangedEventHandler>(); var commandSender = new RabbitCommandBus(connectionFactory, messageSerializer, messageHandlerExecutionContext, rabbitExchangeName, ExchangeType.Topic); var commandSubscriber = new RabbitCommandBus(connectionFactory, messageSerializer, messageHandlerExecutionContext, rabbitExchangeName, ExchangeType.Topic, rabbitCommandQueueName); commandSubscriber.Subscribe <PostTextCommand, PostTextCommandHandler>(); services.AddSingleton <IEventSubscriber>(eventSubscriber); services.AddSingleton <ICommandSender>(commandSender); services.AddSingleton <ICommandSubscriber>(commandSubscriber); // Domain Repository var eventStorageConfig = new AdoNetEventStoreConfiguration(eventStoreConnectionString); var objectSerializer = new ObjectJsonSerializer(); services.AddSingleton <ISnapshotProvider, SuppressedSnapshotProvider>(); services.AddTransient <IEventPublisher>(x => new RabbitEventBus(connectionFactory, messageSerializer, messageHandlerExecutionContext, rabbitExchangeName, ExchangeType.Topic)); services.AddTransient <IEventStore>(x => new SqlServerEventStore(eventStorageConfig, objectSerializer)); services.AddTransient <IDomainRepository, EventSourcingDomainRepository>(); // Add framework services. services.AddMvc(); }
public void LoadEventsWithMinMaxSequenceTest() { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); var event1 = new NameChangedEvent("daxnet") { Sequence = 1 }; var event2 = new TitleChangedEvent("title") { Sequence = 2 }; var event3 = new RegisteredEvent() { Sequence = 3 }; event1.AttachTo(employee); event2.AttachTo(employee); event3.AttachTo(employee); var storeConfig = new AdoNetEventStoreConfiguration(SQLServerFixture.ConnectionString, new GuidKeyGenerator()); var payloadSerializer = new ObjectJsonSerializer(); var store = new SqlServerEventStore(storeConfig, payloadSerializer); store.Save(new List <DomainEvent> { event1, event2, event3 }); var events = store.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId, 1, 3).ToList(); Assert.Equal(3, events.Count); Assert.IsType <NameChangedEvent>(events[0]); Assert.IsType <TitleChangedEvent>(events[1]); Assert.IsType <RegisteredEvent>(events[2]); }
public PostgreSqlEventStore(AdoNetEventStoreConfiguration config, IObjectSerializer payloadSerializer) : base(config, payloadSerializer) { }
public void OverriddenTableNameTest() { var config = new AdoNetEventStoreConfiguration("conn", "table"); Assert.Equal("table", config.TableName); }
public void DefaultFieldNameTest3() { var config = new AdoNetEventStoreConfiguration("conn"); Assert.Null(config.GetFieldName("EventClrType1")); }
public void DefaultFieldNameTest2() { var config = new AdoNetEventStoreConfiguration("conn"); Assert.Equal("EVENTCLRTYPE", config.GetFieldName("EventClrType")); }
public void DefaultTableNameTest() { var config = new AdoNetEventStoreConfiguration("conn"); Assert.Equal("EVENTS", config.TableName); }
public void AssignConnectionStringTest() { var config = new AdoNetEventStoreConfiguration("conn"); Assert.Equal("conn", config.ConnectionString); }
public SqlServerEventStore(AdoNetEventStoreConfiguration config, IObjectSerializer payloadSerializer) : base(config, payloadSerializer) { }