示例#1
0
        public void MarkAllChangesAsCommited_WhenInvoked_MustClearUncommitedCollection()
        {
            // Arrange
            var subject = new TestAggregate();

            subject.InvokeRaiseEvent(new TestEvent1());

            // Act
            subject.MarkAllChangesAsCommited();

            // Assert
            Assert.That(subject.GetUncommitedChanges(), Is.Empty);
        }
        public void LoadFromHistory_WhenInvoked_MustSetVersionToIndexOfLastAppliedEvent(int numberOfEvents)
        {
            // Arrange
            var events = Enumerable.Range(0, numberOfEvents)
                         .Select(x => new TestEvent1())
                         .ToArray();
            var subject = new TestAggregate();

            // Act
            subject.LoadFromHistory(events);

            // Assert
            Assert.That(subject.Version, Is.EqualTo(numberOfEvents - 1));
        }
        public void LoadFromHistory_WhenInvoked_MustApplyEvents()
        {
            // Arrange
            var testEvent1 = new TestEvent1();
            var testEvent2 = new TestEvent2();
            var expected   = new IEvent[] { testEvent1, testEvent2 };
            var subject    = new TestAggregate();

            // Act
            subject.LoadFromHistory(expected);

            // Assert
            Assert.That(subject.AppliedEvents, Is.EqualTo(expected));
        }
        public void LoadFromHistory_WhenInvoked_MustNotAddEventsToUnpublishedEventsCollection()
        {
            // Arrange
            var testEvent1 = new TestEvent1();
            var testEvent2 = new TestEvent2();
            var events     = new IEvent[] { testEvent1, testEvent2 };
            var subject    = new TestAggregate();

            // Act
            subject.LoadFromHistory(events);

            // Assert
            Assert.That(subject.GetUncommitedChanges(), Is.Empty);
        }
示例#5
0
        public void MarkAllChangesAsCommited_WhenInvoked_MustIncrementVersionForEveryCommitedEvent()
        {
            // Arrange
            var subject = new TestAggregate();

            subject.LoadFromHistory(new IEvent[] { new TestEvent1(), new TestEvent2() });
            subject.InvokeRaiseEvent(new TestEvent1());
            subject.InvokeRaiseEvent(new TestEvent1());

            // Act
            subject.MarkAllChangesAsCommited();

            // Assert
            Assert.That(subject.Version, Is.EqualTo(3));
        }