Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
            }
        }