コード例 #1
0
        public void EventsAreSortedBySequenceBeforeBeingAppliedToTheAggregateRoot()
        {
            var aggregateRoot = new MyAggregateRoot();
            var domainEvents  = new List <HandlerThatMeetsConventionEvent>
            {
                new HandlerThatMeetsConventionEvent {
                    Sequence = 5
                },
                new HandlerThatMeetsConventionEvent {
                    Sequence = 1
                },
                new HandlerThatMeetsConventionEvent {
                    Sequence = 100
                },
                new HandlerThatMeetsConventionEvent {
                    Sequence = 2
                }
            };

            aggregateRoot.LoadFromHistoricalEvents(domainEvents.ToArray());

            Assert.AreEqual(1, aggregateRoot.EventIds[0]);
            Assert.AreEqual(2, aggregateRoot.EventIds[1]);
            Assert.AreEqual(5, aggregateRoot.EventIds[2]);
            Assert.AreEqual(100, aggregateRoot.EventIds[3]);
        }
コード例 #2
0
        public void HandlerIsCalledWhenHandlerIsProtectedAndEventIsApplied()
        {
            var domainEvent   = new ProtectedHandlerThatMeetsConventionEvent();
            var aggregateRoot = new MyAggregateRoot();

            aggregateRoot.Apply(domainEvent);

            Assert.IsTrue(aggregateRoot.OnProtectedHandlerThatMeetsConventionCalled);
        }
コード例 #3
0
        public void EventsAreSortedBySequenceBeforeBeingAppliedToTheAggregateRoot()
        {
            var aggregateRoot = new MyAggregateRoot();
            var domainEvents = new List<HandlerThatMeetsConventionEvent>
                                   {
                                       new HandlerThatMeetsConventionEvent {Sequence = 5},
                                       new HandlerThatMeetsConventionEvent {Sequence = 1},
                                       new HandlerThatMeetsConventionEvent {Sequence = 100},
                                       new HandlerThatMeetsConventionEvent {Sequence = 2}
                                   };

            aggregateRoot.LoadFromHistoricalEvents(domainEvents.ToArray());

            Assert.AreEqual(1, aggregateRoot.EventIds[0]);
            Assert.AreEqual(2, aggregateRoot.EventIds[1]);
            Assert.AreEqual(5, aggregateRoot.EventIds[2]);
            Assert.AreEqual(100, aggregateRoot.EventIds[3]);
        }
コード例 #4
0
        public void HandlerIsCalledWhenHandlerIsPrivateAndEventIsApplied()
        {
            var domainEvent = new PrivateHandlerThatMeetsConventionEvent();
            var aggregateRoot = new MyAggregateRoot();

            aggregateRoot.Apply(domainEvent);

            Assert.IsTrue(aggregateRoot.OnPrivateHandlerThatMeetsConventionCalled);
        }