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 ShouldAppendDomainEventToEndOfStream()
            {
                TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid());

                var stream = new DomainEventStream(aggregateRoot.Id);

                stream.Should().HaveCount(0);

                var aggregateRootDomainEvent = new AggregateRootChangedDomainEvent(aggregateRoot.Id, Guid.NewGuid());
                IDomainEventStream result    = stream.AppendDomainEvent(aggregateRootDomainEvent);

                result.Should().HaveCount(1);
            }
            public void ShouldThrowIfAggregateRootIdDoesNotMatch()
            {
                TestAggregateRoot aggregateRoot1 = new TestAggregateRoot(Guid.NewGuid());
                TestAggregateRoot aggregateRoot2 = new TestAggregateRoot(Guid.NewGuid());

                var aggregateRoot1Stream = new DomainEventStream(aggregateRoot1.Id);

                aggregateRoot1Stream.Should().HaveCount(0);

                var aggregateRoot2DomainEvent = new AggregateRootChangedDomainEvent(aggregateRoot2.Id, Guid.NewGuid());

                // Append domain event of aggregate 2 to stream of aggregate 1.
                aggregateRoot1Stream.Invoking(s => s.AppendDomainEvent(aggregateRoot2DomainEvent)).Should().Throw <InvalidOperationException>();
            }