public void SaveAggregateRootAndSubscribeEventTest() { using (var eventPublisher = new EventBus(connectionFactory, serializer, this.GetType().Name)) using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), serializer)) using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher)) { int eventsReceived = 0; var ackCnt = 0; var subscriber = (IEventSubscriber)eventPublisher; subscriber.MessageReceived += (a, b) => eventsReceived++; subscriber.MessageAcknowledged += (x, y) => ackCnt++; subscriber.Subscribe(); var aggregateRootId = Guid.NewGuid(); var employee = new Employee { Id = aggregateRootId }; employee.ChangeName("daxnet"); employee.ChangeTitle("developer"); repository.Save <Guid, Employee>(employee); while (ackCnt < 2) { ; } Assert.Equal(2, eventsReceived); } }
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 PostgreSqlEventStoreFactory() { //Brett var configuration = Configuration.Get(); //var helper = new PostgreSqlTestHelper(configuration); //PostgreSqlTestHelper //helper.EnsureTestDatabaseExists(); ////var connectionString = helper.ConnectionString; //helper.DropTable("events"); //_eventStore = new PostgreSqlEventStore(configuration, MsSqlTestHelper.TestDbName, "events"); //_eventStore.DropEvents(); //var helper = new PostgreSqlTestHelper(configuration); PostgreSqlTestHelper.DropTable("Events"); //PostgreSqlTestHelper.DropTable("Events"); //var connectionString = configuration[ PostgreSqlTestHelper.PostgreSqlConnectionString]; _eventStore = new PostgreSqlEventStore(configuration, PostgreSqlTestHelper.TestDbName, "events"); _eventStore.DropEvents(); //orig //PostgreSqlTestHelper.DropTable("Events"); //var connectionString = PostgreSqlTestHelper.PostgreSqlConnectionString; //_eventStore = new PostgreSqlEventStore(connectionString, "Events"); //_eventStore.DropEvents(); }
public void SaveAggregateRootAndSubscribeEventTest() { var serviceCollection = new ServiceCollection(); var names = new List <string>(); serviceCollection.AddSingleton(names); var executionContext = new ServiceProviderMessageHandlerExecutionContext(serviceCollection); using (var eventPublisher = new RabbitEventBus(connectionFactory, messageSerializer, executionContext, this.GetType().Name)) using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), eventStoreSerializer)) using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher, snapshotProvider)) { int eventsReceived = 0; var ackCnt = 0; var subscriber = (IEventSubscriber)eventPublisher; subscriber.MessageReceived += (a, b) => eventsReceived++; subscriber.MessageAcknowledged += (x, y) => ackCnt++; subscriber.Subscribe <NameChangedEvent, NameChangedEventHandler>(); subscriber.Subscribe <TitleChangedEvent, TitleChangedEventHandler>(); var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); employee.ChangeName("daxnet"); employee.ChangeTitle("developer"); repository.Save <Guid, Employee>(employee); while (ackCnt < 2) { ; } Assert.Equal(2, eventsReceived); } }
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()); }
public PostgreSqlEventStoreFactory() { PostgreSqlTestHelper.DropTable("Events"); var connectionString = PostgreSqlTestHelper.PostgreSqlConnectionString; _eventStore = new PostgreSqlEventStore(connectionString, "Events"); _eventStore.DropEvents(); }
public void SaveAggregateRootTest() { using (var eventPublisher = new EventBus(connectionFactory, messageSerializer, this.GetType().Name)) using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), eventStoreSerializer)) using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher, snapshotProvider)) { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); employee.ChangeName("daxnet"); employee.ChangeTitle("developer"); Assert.Equal(3, employee.Version); repository.Save <Guid, Employee>(employee); Assert.Equal(3, employee.Version); } }
public void GetByVersionTest1() { using (var eventPublisher = new EventBus(connectionFactory, messageSerializer, this.GetType().Name)) using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), eventStoreSerializer)) using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher, snapshotProvider)) { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); employee.ChangeName("daxnet"); employee.ChangeTitle("developer"); employee.Register(); repository.Save <Guid, Employee>(employee); var employee2 = repository.GetById <Guid, Employee>(aggregateRootId, 2); // Load 2 events as the first one is the aggregate created event. Assert.Equal(employee.Name, employee2.Name); Assert.Null(employee2.Title); Assert.Equal(DateTime.MinValue, employee2.DateRegistered); } }
public void EventSequenceAfterSaveTest() { using (var eventPublisher = new EventBus(connectionFactory, messageSerializer, this.GetType().Name)) using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), eventStoreSerializer)) using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher, snapshotProvider)) { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); employee.ChangeName("daxnet"); employee.ChangeTitle("developer"); repository.Save <Guid, Employee>(employee); var events = eventStore.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId).ToList(); Assert.Equal(3, events.Count); Assert.Equal(1, (events[0] as IDomainEvent).Sequence); Assert.Equal(2, (events[1] as IDomainEvent).Sequence); Assert.Equal(3, (events[2] as IDomainEvent).Sequence); } }
public void LoadAggregateRootTest() { using (var eventPublisher = new EventBus(connectionFactory, serializer, this.GetType().Name)) using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), serializer)) using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher)) { var aggregateRootId = Guid.NewGuid(); var employee = new Employee { Id = aggregateRootId }; employee.ChangeName("daxnet"); employee.ChangeTitle("developer"); repository.Save <Guid, Employee>(employee); var employee2 = repository.GetById <Guid, Employee>(aggregateRootId); Assert.Equal("daxnet", employee2.Name); Assert.Equal("Sr. developer", employee2.Title); Assert.Equal(2, employee2.Version); } }
public void LoadAggregateRootTest() { var serviceCollection = new ServiceCollection(); var executionContext = new ServiceProviderMessageHandlerExecutionContext(serviceCollection); using (var eventPublisher = new RabbitEventBus(connectionFactory, messageSerializer, executionContext, this.GetType().Name)) using (var eventStore = new PostgreSqlEventStore(new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()), eventStoreSerializer)) using (var repository = new EventSourcingDomainRepository(eventStore, eventPublisher, snapshotProvider)) { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); employee.ChangeName("daxnet"); employee.ChangeTitle("developer"); repository.Save <Guid, Employee>(employee); var employee2 = repository.GetById <Guid, Employee>(aggregateRootId); Assert.Equal("daxnet", employee2.Name); Assert.Equal("Sr. developer", employee2.Title); Assert.Equal(3, employee2.Version); } }