public void ShouldAppendDomainEventsToEndOfStream()
            {
                TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid());
                IAggregateRoot    explicitCast  = aggregateRoot;

                // Apply 3 domain events.
                aggregateRoot.ChangeMe(Guid.NewGuid());
                aggregateRoot.ChangeMe(Guid.NewGuid());
                aggregateRoot.ChangeMe(Guid.NewGuid());

                DomainEventStream stream1 = (DomainEventStream)explicitCast.GetDomainEventsMarkedForCommit();

                // Clear domain events.
                explicitCast.MarkDomainEventsAsCommitted();

                // Apply 3 domain events.
                aggregateRoot.ChangeMe(Guid.NewGuid());
                aggregateRoot.ChangeMe(Guid.NewGuid());
                aggregateRoot.ChangeMe(Guid.NewGuid());

                DomainEventStream stream2 = (DomainEventStream)explicitCast.GetDomainEventsMarkedForCommit();

                // Append 2 streams.
                DomainEventStream result = stream1.AppendDomainEventStream(stream2);

                result.Should().HaveCount(6);
            }
            public void ShouldRemoveAllAppliedDomainEvents()
            {
                TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid());

                // Apply 3 domain events
                aggregateRoot.ChangeMe(Guid.NewGuid());
                aggregateRoot.ChangeMe(Guid.NewGuid());
                aggregateRoot.ChangeMe(Guid.NewGuid());

                // Check
                IAggregateRoot explicitCast = aggregateRoot;

                explicitCast.GetDomainEventsMarkedForCommit().Should().HaveCount(3);

                // Clear
                explicitCast.MarkDomainEventsAsCommitted();
                explicitCast.GetDomainEventsMarkedForCommit().Should().HaveCount(0);
            }
            public void ShouldIncludeAppliedDomainEvent()
            {
                TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid());

                // Apply 3 domain events
                aggregateRoot.ChangeMe(Guid.NewGuid());
                aggregateRoot.ChangeMe(Guid.NewGuid());
                aggregateRoot.ChangeMe(Guid.NewGuid());

                IAggregateRoot explicitCast = aggregateRoot;

                explicitCast.GetDomainEventsMarkedForCommit().Should().HaveCount(3);
            }
            public void ShouldThrowIfAggregateRootIdDoesNotMatch()
            {
                TestAggregateRoot aggregateRoot1             = new TestAggregateRoot(Guid.NewGuid());
                TestAggregateRoot aggregateRoot2             = new TestAggregateRoot(Guid.NewGuid());
                IAggregateRoot    aggregateRoot1ExplicitCast = aggregateRoot1;
                IAggregateRoot    aggregateRoot2ExplicitCast = aggregateRoot2;

                // Apply 3 domain events.
                aggregateRoot1.ChangeMe(Guid.NewGuid());
                aggregateRoot1.ChangeMe(Guid.NewGuid());
                aggregateRoot1.ChangeMe(Guid.NewGuid());

                DomainEventStream stream1 = (DomainEventStream)aggregateRoot1ExplicitCast.GetDomainEventsMarkedForCommit();

                // Apply 3 domain events.
                aggregateRoot2.ChangeMe(Guid.NewGuid());
                aggregateRoot2.ChangeMe(Guid.NewGuid());
                aggregateRoot2.ChangeMe(Guid.NewGuid());

                DomainEventStream stream2 = (DomainEventStream)aggregateRoot2ExplicitCast.GetDomainEventsMarkedForCommit();

                // Append 2 streams.
                stream1.Invoking(s1 => s1.AppendDomainEventStream(stream2)).Should().Throw <InvalidOperationException>();
            }