コード例 #1
0
        public void When_events_are_added_having_defined_SequenceNumbers_then_the_ids_are_maintained()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent { SequenceNumber = 3 });
            events.Add(new TestEvent { SequenceNumber = 2 });
            events.Add(new TestEvent { SequenceNumber = 1 });

            events.First().SequenceNumber.Should().Be(events.Last().SequenceNumber - 2);
        }
コード例 #2
0
        public void When_events_are_added_with_with_gaps_in_their_SequenceNumbers_then_they_are_assigned_the_next_sequential_value()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent { SequenceNumber = 22 });
            events.Add(new TestEvent { SequenceNumber = 33 });
            events.Add(new TestEvent());

            events.Last().SequenceNumber.Should().Be(34);
        }
コード例 #3
0
        public void EventSequence_version_returns_current_highest_SequenceNumber()
        {
            var sequence = new EventSequence(Guid.NewGuid());

            sequence.Add(new TestEvent());
            sequence.Add(new TestEvent());
            sequence.Add(new TestEvent());

            sequence.Version.Should().Be(3);
        }
コード例 #4
0
        public void Events_are_ordered_by_SequenceNumber_regardless_of_the_order_in_which_they_are_added()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent { SequenceNumber = 3 });
            events.Add(new TestEvent { SequenceNumber = 2 });
            events.Add(new TestEvent { SequenceNumber = 1 });
            events.Add(new TestEvent { SequenceNumber = 4 });

            events.Select(e => e.SequenceNumber).Should().BeInAscendingOrder();
        }
コード例 #5
0
        public void Events_added_out_of_order_do_not_have_their_SequenceNumbers_changed()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent { SequenceNumber = 3, Data = "3" });
            events.Add(new TestEvent { SequenceNumber = 2, Data = "2" });
            events.Add(new TestEvent { SequenceNumber = 1, Data = "1" });
            events.Add(new TestEvent { SequenceNumber = 4, Data = "4" });

            events.Cast<TestEvent>().Select(e => e.Data)
                  .SequenceEqual(new[] { "1", "2", "3", "4" });
        }
コード例 #6
0
        public void When_events_are_added_without_defined_SequenceNumbers_then_they_are_assigned_the_next_sequential_value()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent {
                SequenceNumber = 2
            });
            events.Add(new TestEvent());
            events.Add(new TestEvent());

            events.Last().SequenceNumber.Should().Be(4);
        }
コード例 #7
0
        public void When_an_event_with_an_already_present_SequenceNumber_is_added_then_it_throws()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent {
                SequenceNumber = 1
            });

            Action addAgain = () =>
                              events.Add(new TestEvent {
                SequenceNumber = 1
            });

            addAgain.ShouldThrow <ArgumentException>();
        }
コード例 #8
0
        public void When_events_are_added_having_defined_SequenceNumbers_then_the_ids_are_maintained()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent {
                SequenceNumber = 3
            });
            events.Add(new TestEvent {
                SequenceNumber = 2
            });
            events.Add(new TestEvent {
                SequenceNumber = 1
            });

            events.First().SequenceNumber.Should().Be(events.Last().SequenceNumber - 2);
        }
コード例 #9
0
        public void EventSequence_version_returns_current_highest_SequenceNumber_when_events_are_out_of_order()
        {
            var sequence = new EventSequence(Guid.NewGuid());

            sequence.Add(new TestEvent {
                SequenceNumber = 4
            });
            sequence.Add(new TestEvent {
                SequenceNumber = 9000
            });
            sequence.Add(new TestEvent {
                SequenceNumber = 9
            });

            sequence.Version.Should().Be(9000);
        }
コード例 #10
0
        public void When_events_are_added_having_undefined_aggregate_id_then_the_EventSequence_SourceId_is_assigned()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent());

            events.First().AggregateId.Should().Be(events.AggregateId);
        }
コード例 #11
0
        public void When_events_are_added_having_undefined_aggregate_id_then_the_EventSequence_SourceId_is_assigned()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent());

            events.First().AggregateId.Should().Be(events.AggregateId);
        }
コード例 #12
0
        public void Events_are_ordered_by_SequenceNumber_regardless_of_the_order_in_which_they_are_added()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent {
                SequenceNumber = 3
            });
            events.Add(new TestEvent {
                SequenceNumber = 2
            });
            events.Add(new TestEvent {
                SequenceNumber = 1
            });
            events.Add(new TestEvent {
                SequenceNumber = 4
            });

            events.Select(e => e.SequenceNumber).Should().BeInAscendingOrder();
        }
コード例 #13
0
        public void Events_added_out_of_order_do_not_have_their_SequenceNumbers_changed()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent {
                SequenceNumber = 3, Data = "3"
            });
            events.Add(new TestEvent {
                SequenceNumber = 2, Data = "2"
            });
            events.Add(new TestEvent {
                SequenceNumber = 1, Data = "1"
            });
            events.Add(new TestEvent {
                SequenceNumber = 4, Data = "4"
            });

            events.Cast <TestEvent>().Select(e => e.Data)
            .SequenceEqual(new[] { "1", "2", "3", "4" });
        }
コード例 #14
0
        public void When_an_event_with_an_already_present_SequenceNumber_is_added_then_it_throws()
        {
            var events = new EventSequence(Guid.NewGuid());

            events.Add(new TestEvent { SequenceNumber = 1 });

            Action addAgain = () =>
                              events.Add(new TestEvent { SequenceNumber = 1 });

            addAgain.ShouldThrow<ArgumentException>();
        }
コード例 #15
0
        public void EventSequence_version_returns_current_highest_SequenceNumber_when_events_are_out_of_order()
        {
            var sequence = new EventSequence(Guid.NewGuid());

            sequence.Add(new TestEvent { SequenceNumber = 4 });
            sequence.Add(new TestEvent { SequenceNumber = 9000 });
            sequence.Add(new TestEvent { SequenceNumber = 9 });

            sequence.Version.Should().Be(9000);
        }
コード例 #16
0
        public void EventSequence_version_returns_current_highest_SequenceNumber()
        {
            var sequence = new EventSequence(Guid.NewGuid());

            sequence.Add(new TestEvent());
            sequence.Add(new TestEvent());
            sequence.Add(new TestEvent());

            sequence.Version.Should().Be(3);
        }