/// <summary> /// Constructor. /// </summary> /// <param name="domainEventStore">Decorated domain event store.</param> /// <param name="publisher">Event publisher.</param> public PublishingDomainEventAsyncStore(IDomainEventAsyncStore <TAggregate, TAggregateId> domainEventStore, IEventPublisher publisher) { _domainEventStore = domainEventStore; _publisher = publisher; // Subscribe to any errors in publishing. _publisher.OnError += (e, ex) => { OnPublishError((IDomainEvent)e, ex); }; }
public async Task Should_Append_To_Domain_Event_Store() { IDomainEventAsyncStore <TestAggregate, Guid> eventStore = Factory.CreateEventAsyncStore <TestAggregate, Guid>(); // Create aggregate. TestAggregate aggregate = new TestAggregate(Guid.NewGuid()); await eventStore.SaveAsync(aggregate); IDomainEventStream <Guid> stream = await eventStore.GetDomainEventStreamAsync(aggregate.Id); Assert.NotNull(stream); Assert.Equal(aggregate.Id, stream.AggregateId); Assert.Equal(1, stream.DomainEventCount); }
public async Task GetDomainEventStreamAsync_Should_Retrieve_Aggregate_Stream() { IDomainEventAsyncStore <TestAggregate, Guid> eventStore = Factory.CreateEventAsyncStore <TestAggregate, Guid>(); // Create and modify aggregate. TestAggregate aggregate = new TestAggregate(Guid.NewGuid()); aggregate.ExecuteSomeOperation("I was modified!~"); await eventStore.SaveAsync(aggregate); IDomainEventStream <Guid> stream = await eventStore.GetDomainEventStreamAsync(aggregate.Id); Assert.NotNull(stream); Assert.Equal(aggregate.Id, stream.AggregateId); // 2 domain events in total: Created + Modified events. Assert.Equal(2, stream.DomainEventCount); // Stream starts from version 1 to 2. Assert.Equal(1, stream.BeginVersion); Assert.Equal(2, stream.EndVersion); }
public TestAggregateAsyncRepository(IDomainEventAsyncStore <TestAggregate, Guid> domainEventStore) { DomainEventStore = domainEventStore; }
public static IEventSourcedAggregateAsyncRepository <TestAggregate, Guid> CreateTestAggregateAsyncRepository(IDomainEventAsyncStore <TestAggregate, Guid> domainEventStore) { return(new TestAggregateAsyncRepository(domainEventStore)); }