Exemplo n.º 1
0
        public void Applying_an_event_should_not_effect_the_initial_version()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.InitialVersion.Should().Be(0);
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.InitialVersion.Should().Be(0);
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.InitialVersion.Should().Be(0);
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
        }
Exemplo n.º 2
0
        public void It_could_not_be_loaded_from_history_when_it_already_contains_uncommitted_events()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            var    history = new[] { new HandledEvent(), new HandledEvent() };
            Action act     = () => theAggregate.InitializeFromHistory(history);

            act.ShouldThrow <InvalidOperationException>();
        }
Exemplo n.º 3
0
        public void Applying_an_event_should_at_it_to_the_uncommited_events()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.GetUncommittedEvents().Count().Should().Be(1);

            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.GetUncommittedEvents().Count().Should().Be(2);
        }
Exemplo n.º 4
0
        public void Getting_the_uncommitted_via_the_IEventSource_interface_should_return_the_same_as_directly()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            var directResult       = theAggregate.GetUncommittedEvents();
            var viaInterfaceResult = ((IEventSource)theAggregate).GetUncommittedEvents();

            directResult.Should().BeEquivalentTo(viaInterfaceResult);
        }
Exemplo n.º 5
0
        public void Applying_an_event_should_at_it_to_the_uncommited_events()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.GetUncommittedEvents().Count().Should().Be(1);

            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.GetUncommittedEvents().Count().Should().Be(2);
        }
Exemplo n.º 6
0
        public void Accepting_the_changes_should_clear_the_uncommitted_events()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.AcceptChanges();

            theAggregate.GetUncommittedEvents().Should().BeEmpty();
        }
Exemplo n.º 7
0
        public void Applying_an_event_should_not_effect_the_initial_version()
        {
            using (NcqrsEnvironment.Get <IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                var theAggregate = new MyAggregateRoot();

                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
            }
        }
Exemplo n.º 8
0
        public void Accepting_the_changes_should_clear_the_uncommitted_events()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.AcceptChanges();

            theAggregate.GetUncommittedEvents().Should().BeEmpty();
        }
Exemplo n.º 9
0
        public void Applying_an_event_should_not_effect_the_initial_version()
        {
            using (NcqrsEnvironment.Get<IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                var theAggregate = new MyAggregateRoot();

                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
            }
        }
Exemplo n.º 10
0
        public void Applying_an_event_should_at_it_to_the_uncommited_events()
        {
            using (NcqrsEnvironment.Get<IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                var theAggregate = new MyAggregateRoot();

                theAggregate.MethodThatCausesAnEventThatHasAHandler();

                theAggregate.GetUncommittedEvents().Count().Should().Be(1);

                theAggregate.MethodThatCausesAnEventThatHasAHandler();

                theAggregate.GetUncommittedEvents().Count().Should().Be(2);
            }
        }
Exemplo n.º 11
0
        public void Applying_an_event_should_affect_the_version()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.Version.Should().Be(0);

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.Version.Should().Be(1);
            theAggregate.GetUncommittedEvents().Last().EventSequence.Should().Be(1);

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.Version.Should().Be(2);
            theAggregate.GetUncommittedEvents().Last().EventSequence.Should().Be(2);

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
        }
Exemplo n.º 12
0
        public void Accepting_the_changes_should_set_the_initial_version_to_the_new_version()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.InitialVersion.Should().Be(0);

            theAggregate.AcceptChanges();

            theAggregate.InitialVersion.Should().Be(5);
        }
Exemplo n.º 13
0
        public void Applying_an_event_when_there_is_no_unit_of_work_should_not_cause_an_exception()
        {
            var    theAggregate = new MyAggregateRoot();
            Action act          = () => theAggregate.MethodThatCausesAnEventThatHasAHandler();

            act.ShouldNotThrow();
        }
Exemplo n.º 14
0
        public void Accepting_the_changes_should_set_the_initial_version_to_the_new_version()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.InitialVersion.Should().Be(0);

            theAggregate.AcceptChanges();

            theAggregate.InitialVersion.Should().Be(5);
        }
Exemplo n.º 15
0
        public void Applying_an_event_should_affect_the_version()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.Version.Should().Be(0);

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.Version.Should().Be(1);
            theAggregate.GetUncommittedEvents().Last().EventSequence.Should().Be(1);

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.Version.Should().Be(2);
            theAggregate.GetUncommittedEvents().Last().EventSequence.Should().Be(2);

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
        }
Exemplo n.º 16
0
        public void Accepting_the_changes_should_clear_the_uncommitted_events()
        {
            using (NcqrsEnvironment.Get<IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                var theAggregate = new MyAggregateRoot();

                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.MethodThatCausesAnEventThatHasAHandler();

                theAggregate.AcceptChanges();

                theAggregate.GetUncommittedEvents().Should().BeEmpty();
            }
        }
Exemplo n.º 17
0
        public void Applying_an_event_should_call_the_event_handler_only_once()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.FooEventHandlerInvokeCount.Should().Be(1);
        }
Exemplo n.º 18
0
        public void Accepting_the_changes_should_set_the_initial_version_to_the_new_version()
        {
            using (NcqrsEnvironment.Get<IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                var theAggregate = new MyAggregateRoot();

                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.MethodThatCausesAnEventThatHasAHandler();

                theAggregate.InitialVersion.Should().Be(0);

                theAggregate.AcceptChanges();

                theAggregate.InitialVersion.Should().Be(5);
            }
        }
Exemplo n.º 19
0
        public void Applying_an_event_to_an_agg_root_with_history_should_call_the_event_handler_only_once()
        {
            var theAggregate = new MyAggregateRoot();

            var event1 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 1, DateTime.UtcNow);
            var event2 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 2, DateTime.UtcNow);
            var event3 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 3, DateTime.UtcNow);
            var event4 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 4, DateTime.UtcNow);
            var event5 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 5, DateTime.UtcNow);

            IEnumerable <SourcedEvent> history = new[] { event1, event2, event3, event4, event5 };

            theAggregate.InitializeFromHistory(history);

            var eventHandlerCountAfterInitialization = theAggregate.FooEventHandlerInvokeCount;

            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.FooEventHandlerInvokeCount.Should().Be(eventHandlerCountAfterInitialization + 1);
        }
Exemplo n.º 20
0
        public void Applying_an_event_to_an_agg_root_with_history_should_call_the_event_handler_only_once()
        {
            var theAggregate = new MyAggregateRoot();

            var event1 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 1, DateTime.UtcNow);
            var event2 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 2, DateTime.UtcNow);
            var event3 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 3, DateTime.UtcNow);
            var event4 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 4, DateTime.UtcNow);
            var event5 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 5, DateTime.UtcNow);

            IEnumerable<SourcedEvent> history = new[] { event1, event2, event3, event4, event5 };

            theAggregate.InitializeFromHistory(history);

            var eventHandlerCountAfterInitialization = theAggregate.FooEventHandlerInvokeCount;

            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.FooEventHandlerInvokeCount.Should().Be(eventHandlerCountAfterInitialization + 1);
        }
Exemplo n.º 21
0
        public void Applying_an_event_when_there_is_no_unit_of_work_should_cause_an_exception()
        {
            var theAggregate = new MyAggregateRoot();
            Action act = ()=> theAggregate.MethodThatCausesAnEventThatHasAHandler();

            act.ShouldThrow<NoUnitOfWorkAvailableInThisContextException>();
        }
Exemplo n.º 22
0
        public void Applying_an_event_should_not_effect_the_initial_version()
        {
            var theAggregate = new MyAggregateRoot();

                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.InitialVersion.Should().Be(0);
                theAggregate.MethodThatCausesAnEventThatHasAHandler();
        }
Exemplo n.º 23
0
        public void It_could_not_be_loaded_from_history_when_it_already_contains_uncommitted_events()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            var history = new[] {new HandledEvent(), new HandledEvent()};
            Action act = () => theAggregate.InitializeFromHistory(history);

            act.ShouldThrow<InvalidOperationException>();
        }
Exemplo n.º 24
0
        public void Applying_an_event_should_the_the_version()
        {
            using (NcqrsEnvironment.Get<IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                var theAggregate = new MyAggregateRoot();

                theAggregate.Version.Should().Be(0);

                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.Version.Should().Be(1);
                theAggregate.GetUncommittedEvents().Last().EventSequence.Should().Be(1);

                theAggregate.MethodThatCausesAnEventThatHasAHandler();
                theAggregate.Version.Should().Be(2);
                theAggregate.GetUncommittedEvents().Last().EventSequence.Should().Be(2);

                theAggregate.MethodThatCausesAnEventThatHasAHandler();
            }
        }
Exemplo n.º 25
0
        public void Getting_the_uncommitted_via_the_IEventSource_interface_should_return_the_same_as_directly()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();
            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            var directResult = theAggregate.GetUncommittedEvents();
            var viaInterfaceResult = ((IEventSource) theAggregate).GetUncommittedEvents();
            directResult.Should().BeEquivalentTo(viaInterfaceResult);
        }
Exemplo n.º 26
0
 public void Applying_an_event_when_there_is_no_unit_of_work_should_not_cause_an_exception()
 {
     var theAggregate = new MyAggregateRoot();
     Action act = ()=>theAggregate.MethodThatCausesAnEventThatHasAHandler();
     act.ShouldNotThrow();
 }
Exemplo n.º 27
0
        public void Applying_an_event_should_call_the_event_handler_only_once()
        {
            var theAggregate = new MyAggregateRoot();

            theAggregate.MethodThatCausesAnEventThatHasAHandler();

            theAggregate.FooEventHandlerInvokeCount.Should().Be(1);
        }