예제 #1
0
        public void ResolvedUnitOfWorkEventHandlersAreExecutedInCorrectOrder()
        {
            TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid());

            aggregateRoot.ApplyEvent(domainEvent);

            sut.ApplyChanges(aggregateRoot);

            unitOfWorkDomainEventHandler1.Received().Execute(domainEvent, unitOfWork);
            unitOfWorkDomainEventHandler2.Received().Execute(domainEvent, unitOfWork);
        }
        public void OnlyUnitOfWorkEventsAreHandledIfCommitFails()
        {
            TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid());

            aggregateRoot.ApplyEvent(domainEvent1);

            TestAggregateRoot2 aggregateRoot2 = new TestAggregateRoot2(Guid.NewGuid());

            aggregateRoot.ApplyEvent(domainEvent2);

            unitOfWork
            .When(u => u.SaveChanges())
            .Do(callInfo => { throw new OperationCanceledException(); });

            bool exceptionCatched = false;

            try
            {
                sut.ApplyChanges(aggregateRoot, aggregateRoot2);
            }
            catch (OperationCanceledException)
            {
                exceptionCatched = true;
            }

            Assert.IsTrue(exceptionCatched);
            unitOfWorkDomainEventHandler1.Received().Execute(domainEvent1, unitOfWork);
            unitOfWorkDomainEventHandler2.Received().Execute(domainEvent1, unitOfWork);
            unitOfWorkDomainEventHandler1.Received().Execute(domainEvent2, unitOfWork);
            unitOfWorkDomainEventHandler2.Received().Execute(domainEvent2, unitOfWork);
            unitOfWork.Received().SaveChanges();
            domainEventHandler3.DidNotReceive().Execute(domainEvent1);
            domainEventHandler4.DidNotReceive().Execute(domainEvent1);
            domainEventHandler3.DidNotReceive().Execute(domainEvent2);
            domainEventHandler4.DidNotReceive().Execute(domainEvent2);
        }
        public void EventHandlersAreExecutedWithSingleEvent()
        {
            sut.PublishEvent(testEvent1);

            Received.InOrder(() =>
            {
                domainEventHandler1.Received().Execute(testEvent1, unitOfWork);
                domainEventHandler2.Received().Execute(testEvent1, unitOfWork);
                asyncDomainEventHandler1.Received().ExecuteAsync(testEvent1, unitOfWork);
                asyncDomainEventHandler2.Received().ExecuteAsync(testEvent1, unitOfWork);
            });

            domainEventHandler3.DidNotReceive().Execute(Arg.Any <AnotherTestDomainEvent>(), Arg.Any <TestUnitOfWork>());
            asyncDomainEventHandler3.DidNotReceive().ExecuteAsync(Arg.Any <AnotherTestDomainEvent>(), Arg.Any <TestUnitOfWork>());
        }