Example #1
0
        public void aggregate_without_changes_should_build_an_empty_changeset()
        {
            var ticket    = TicketTestFactory.ForTest();
            var persister = (IEventSourcedAggregate)ticket;
            var changeSet = persister.GetChangeSet();

            Assert.NotNull(changeSet);
            Assert.True(changeSet.IsEmpty());
        }
Example #2
0
        public void restoring_incompatible_snapshot_should_return_false()
        {
            var ticket       = TicketTestFactory.ForTest();
            var snaphottable = (ISnaphottable)ticket;
            var snapshot     = new SnapshotInfo(ticket.Id, 2, null, null);
            var restored     = snaphottable.TryRestore(snapshot);

            Assert.False(restored);
        }
Example #3
0
        public void restoring_null_snapshot_should_throw()
        {
            var ticket       = TicketTestFactory.ForTest();
            var snaphottable = (ISnaphottable)ticket;

            Assert.Throws <ArgumentNullException>(() =>
            {
                snaphottable.TryRestore(null);
            });
        }
Example #4
0
        public void persister_should_create_changeset_with_new_events()
        {
            var ticket    = TicketTestFactory.Sold();
            var persister = (IEventSourcedAggregate)ticket;
            var changeSet = persister.GetChangeSet();

            Assert.NotNull(changeSet);
            Assert.False(changeSet.IsEmpty());
            Assert.Equal(1, changeSet.AggregateVersion);
        }
Example #5
0
        public void append_should_increase_version()
        {
            Ticket ticket    = TicketTestFactory.ForTest();
            var    persister = (IEventSourcedAggregate)ticket;
            var    changeSet = new Changeset(1, new TicketSold());

            persister.ApplyChanges(changeSet);

            Assert.True(ticket.IsInitialized);
            Assert.Equal(1, ticket.Version);
            Assert.False(ticket.IsDirty);
        }
Example #6
0
        public void raising_event_should_not_increase_version()
        {
            Ticket ticket = TicketTestFactory.ForTest();

            ticket.Sale();

            var changes = ticket.ExposePendingChangesForTestInspection();

            Assert.Equal(0, ticket.Version);
            Assert.True(ticket.IsDirty);
            Assert.IsType <TicketSold>(changes.Events[0]);
            Assert.True(ticket.ExposedStateForTest.HasBeenSold);
        }
Example #7
0
        public void apply_changes_should_be_idempotent()
        {
            Ticket ticket    = TicketTestFactory.ForTest();
            var    persister = (IEventSourcedAggregate)ticket;
            var    changeSet = new Changeset(1, new object[] { new TicketSold() });

            persister.ApplyChanges(changeSet);
            persister.ApplyChanges(changeSet);

            Assert.True(ticket.IsInitialized);
            Assert.Equal(1, ticket.Version);
            Assert.False(ticket.IsDirty);
        }
Example #8
0
        public void changes_must_be_applied_in_strict_order()
        {
            var ticket    = TicketTestFactory.ForTest();
            var persister = (IEventSourcedAggregate)ticket;

            var first = new Changeset(1, new TicketSold());
            var third = new Changeset(3, new TicketSold());

            persister.ApplyChanges(first);

            var ex = Assert.Throws <AggregateRestoreException>(() =>
            {
                persister.ApplyChanges(third);
            });

            Assert.Equal(2, ex.ExpectedVersion);
            Assert.Equal(3, ex.RestoreVersion);
        }
Example #9
0
        public void persister_should_create_changeset_only_with_new_events()
        {
            var ticket    = TicketTestFactory.ForTest();
            var persister = (IEventSourcedAggregate)ticket;

            var changeSet = new Changeset(1, new TicketSold());

            persister.ApplyChanges(changeSet);

            ticket.Refund();

            changeSet = persister.GetChangeSet();

            Assert.NotNull(changeSet);
            Assert.False(changeSet.IsEmpty());
            Assert.Equal(2, changeSet.AggregateVersion);
            Assert.True(1 == changeSet.Events.Length);
            Assert.IsType <TicketRefunded>(changeSet.Events[0]);
        }