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 ResolvedEventHandlersAreExecutedInCorrectOrder() { TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid()); aggregateRoot.ApplyEvent(domainEvent); sut.ApplyChangesAsync(aggregateRoot).Wait(); Received.InOrder(() => { domainEventHandler1.ExecuteAsync(domainEvent); domainEventHandler2.ExecuteAsync(domainEvent); }); }
public void OnlyUnitOfWorkEventsAreHandledIfCommitFails() { TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid()); aggregateRoot.ApplyEvent(domainEvent); unitOfWork .When(u => u.SaveChanges()) .Do(callInfo => { throw new InvalidOperationException(); }); try { sut.ApplyChanges(aggregateRoot); Assert.Fail("No exception thrown."); } catch (InvalidOperationException) { } unitOfWorkDomainEventHandler1.Received().Execute(domainEvent, unitOfWork); unitOfWorkDomainEventHandler2.Received().Execute(domainEvent, unitOfWork); unitOfWork.Received().SaveChanges(); domainEventHandler3.DidNotReceive().Execute(domainEvent); domainEventHandler4.DidNotReceive().Execute(domainEvent); }
public void MultipleChangesInUnitOfWorkAreSavedOnce() { TestAggregateRoot aggregateRoot1 = new TestAggregateRoot(Guid.NewGuid()); aggregateRoot1.ApplyEvent(domainEvent); TestDomainEvent domainEvent2 = new TestDomainEvent(Guid.NewGuid()); unitOfWorkEventHandlerResolver.ResolveEventHandlers<IUnitOfWorkDomainEventHandler<TestDomainEvent, TestUnitOfWork>>().Returns(unitOfWorkDomainEventHandlers); TestAggregateRoot aggregateRoot2 = new TestAggregateRoot(Guid.NewGuid()); aggregateRoot2.ApplyEvent(domainEvent2); sut.ApplyChanges(new List<TestAggregateRoot> { aggregateRoot1, aggregateRoot2 }); Received.InOrder(() => { unitOfWorkDomainEventHandler1.Execute(domainEvent, unitOfWork); unitOfWorkDomainEventHandler1.Execute(domainEvent2, unitOfWork); unitOfWork.SaveChanges(); }); }
public void ChangesInUnitOfWorkAreSaved() { TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid()); aggregateRoot.ApplyEvent(domainEvent); sut.ApplyChanges(aggregateRoot); unitOfWork.Received().SaveChanges(); }
public void OnlyUnitOfWorkEventsAreHandledIfCommitFails() { TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid()); aggregateRoot.ApplyEvent(domainEvent); unitOfWork .When(u => u.SaveChanges()) .Do(callInfo => { throw new InvalidOperationException(); }); try { sut.ApplyChangesAsync(aggregateRoot).Wait(); Assert.Fail("No exception thrown."); } catch (AggregateException e) { if (e.InnerException == null) { Assert.Fail("Expected inner exception of type AggregateException. No inner exception received."); } if (!(e.InnerException is InvalidOperationException)) { Assert.Fail("Expected inner exception of type AggregateException. Received '{0}'.", e.InnerException); } } unitOfWorkDomainEventHandler1.Received().ExecuteAsync(domainEvent, unitOfWork); unitOfWorkDomainEventHandler2.Received().ExecuteAsync(domainEvent, unitOfWork); unitOfWork.Received().SaveChanges(); domainEventHandler3.DidNotReceive().ExecuteAsync(domainEvent); domainEventHandler4.DidNotReceive().ExecuteAsync(domainEvent); }
private DomainEvent ApplyNewEvent(TestAggregateRoot aggregateRoot) { var domainEvent = new TestDomainEvent(Guid.NewGuid()); aggregateRoot.ApplyEvent(domainEvent); return domainEvent; }