public void ItShouldManageDomainEvents() { var aggregate = new MyAggregate(); aggregate.DoSomething(); var domainEvents = aggregate.FlushDomainEvents().ToList(); Assert.Equal(1, domainEvents.Count); domainEvents = aggregate.FlushDomainEvents().ToList(); Assert.Equal(0, domainEvents.Count); }
public void Should_RemoveEvents_When_EventsHaveBeenConsumed() { // Arrange Guid guid = new Guid(); var myAggregate = new MyAggregate(); // Act myAggregate.DoSomething(guid); myAggregate.ClearDomainEvents(); // Assert Assert.AreEqual(0, myAggregate.DomainEvents.Count); }
public void Should_StoreOneEvent_When_AnEventHappened() { // Arrange Guid guid = new Guid(); var myAggregate = new MyAggregate(); // Act myAggregate.DoSomething(guid); // Assert Assert.AreEqual(1, myAggregate.DomainEvents.Count); foreach (var oneDomainEvent in myAggregate.DomainEvents) { Assert.IsInstanceOfType(oneDomainEvent, typeof(SomethingHappenedEvent)); var somethingHappenedEvent = (SomethingHappenedEvent)oneDomainEvent; Assert.AreEqual(guid, somethingHappenedEvent.Guid); } }