public void Should_Invoke_Registered_Domain_Event_Handler() { TestDomainEventHandler handler = new TestDomainEventHandler(_testOutput); IEventSourcedAggregateRepository <TestAggregate, Guid> repository = Factory.CreateTestAggregateRepository(reg => { reg.Register <TestAggregateCreatedEvent>(() => handler); reg.Register <OperationExecutedEvent>(() => handler); }); TestAggregate aggregate = new TestAggregate(Guid.NewGuid()); aggregate.ExecuteSomeOperation("Test Operation"); repository.Save(aggregate); // Event may not have yet been handled in background. Thread.Sleep(1000); // Aggregate should be stored. TestAggregate storedAggregate = repository.GetById(aggregate.Id); Assert.Equal(aggregate.Id, storedAggregate.Id); // Aggregate should have 2 events. // 1. TestAggregateCreated // 2. TestAggregateModified Assert.Equal(2, handler.HandledEvents.Count); Assert.Contains(handler.HandledEvents, (e) => e is TestAggregateCreatedEvent); Assert.Contains(handler.HandledEvents, (e) => e is OperationExecutedEvent); }
public EFCoreEventSourcedAggregateStore(IEventSourcedAggregateRepository eventSourcedRepository, IEFCoreTransactionCoordinator transactionCoordinator) : base(eventSourcedRepository) { this.transactionCoordinator = transactionCoordinator; transactionCoordinator.AddTransactionParticipant(this); }
public void Should_Trigger_OnError_When_Domain_Event_Handler_Exception_Occurred() { TestDomainEventHandler handler = new TestDomainEventHandler(_testOutput); IEventPublisher publisher = Factory.CreatePublisher(reg => { reg.Register <TestAggregateCreatedEvent>(() => handler); reg.Register <OperationExecutedEvent>(() => handler); }); publisher.OnError += (e, ex) => { _testOutput.WriteLine($"{ex.GetType().Name} occurred while handling {e.GetType().Name} event: {ex.Message}"); Assert.IsType <TestAggregateDomainEventHandlerException>(ex); }; IEventSourcedAggregateRepository <TestAggregate, Guid> repository = Factory.CreateTestAggregateRepository(publisher); TestAggregate aggregate = new TestAggregate(Guid.NewGuid()); // This would trigger a TestAggregateDomainEventHandlerException when handled by TestDomainEventHandler. aggregate.TriggerExceptionOnEventHandler(); repository.Save(aggregate); }
public RecordedAggregate(Guid id, long version, IEnumerable <IDomainEvent> events, IEventSourcedAggregateRepository <TAggregate> repository, IEventDispatcher <TAggregate> eventDispatcher) : base(id, eventDispatcher) { Version = version; Events = events; _repository = repository; }
public CommandDispatcher( IEnumerable <ICommandHandler> commandHandlers, IEventSourcedAggregateRepository aggregateRepository, IEventPublisher eventPublisher) : base(typeof(ICommandHandler <>), commandHandlers) { _aggregateRepository = aggregateRepository; _eventPublisher = eventPublisher; }
public void Should_Retrieve_Aggregate() { IEventSourcedAggregateRepository <TestAggregate, Guid> repository = Factory.CreateTestAggregateRepository(); TestAggregate aggregate = new TestAggregate(Guid.NewGuid()); repository.Save(aggregate); TestAggregate fromRepo = repository.GetById(aggregate.Id); Assert.NotNull(fromRepo); Assert.Equal(aggregate.Id, fromRepo.Id); }
public CreatePexaWorkspaceCommandHandler( CreatePexaWorkspaceCommand.ValidatorCollection validator, IClock clock, IExtendedPexaService pexaService, IEventSourcedAggregateRepository <ActionstepMatter> actionstepMatterRepository, WCADbContext wCADbContext ) { _validator = validator; _clock = clock; _pexaService = pexaService; _actionstepMatterRepository = actionstepMatterRepository; _wCADbContext = wCADbContext; }
public AskQuestionCommandHandler(IEventSourcedAggregateRepository <Question> aggregateRepository, IDate date) { _aggregateRepository = aggregateRepository; _date = date; }
public EventSourcedAggregateStore(IEventSourcedAggregateRepository eventSourcedRepository) { this.eventSourcedRepository = eventSourcedRepository; }
public EventSourcedAggregateStoreTests() { eventSourcedRepository = Substitute.For <IEventSourcedAggregateRepository>(); sut = new EventSourcedAggregateStore(eventSourcedRepository); }
public FakeCommandHandler(IEventSourcedAggregateRepository repository) { _repository = repository; }
public AnswerQuestionCommandHandler(IEventSourcedAggregateRepository <Question> aggregateRepository) { _aggregateRepository = aggregateRepository; }
public UnrecordedAggregate(Guid id, IEventSourcedAggregateRepository <TAggregate> repository, IEventDispatcher <TAggregate> eventDispatcher) : base(id, eventDispatcher) { _repository = repository; }