public async Task GivenAnAggregateWithChangesWhenAggregateSavedIsRaisedThenTheChangesArePropagatedToTheBusAsync() { const int ExpectedTotalChanges = 2; var context = new SerializableMessage(); var aggregate = new SerializableEventCentricAggregateRoot(context); var request = new SetRequest(context, Guid.NewGuid()); var bus = new Mock <IBus>(); var cloner = new TestableCloner(); var repository = new UnversionedMemoryRepository <SerializableEventCentricAggregateRoot>(cloner); var propagator = new DomainEventPropagator <SerializableEventCentricAggregateRoot>(bus.Object, repository); IEnumerable <DomainEvent> changes = Enumerable.Empty <DomainEvent>(); _ = bus .Setup(b => b.PublishAsync( It.IsAny <IEnumerable <DomainEvent> >(), It.IsAny <CancellationToken?>())) .Callback <IEnumerable <DomainEvent>, CancellationToken?>((events, _) => changes = events); aggregate.Set(request); await repository.SaveAsync(aggregate); _ = Assert.Single(changes.OfType <SerializableCreatedDomainEvent>()); _ = Assert.Single(changes.OfType <SerializableSetDomainEvent>()); Assert.Equal(ExpectedTotalChanges, changes.Count()); }
public UnversionedMemoryRepositoryTests() { Cloner = new TestableCloner(); }