public bool Execute(CreateAndAddTwoTestsCommand command) { if (IsNew) { var createdEvent = new TestCreatedEvent(command.AggregateId); var firstTestAddedEvent = new TestAddedEvent(command.FirstTest); var secondTestAddedEvent = new TestAddedEvent(command.SecondTest); EmitAll(createdEvent, firstTestAddedEvent, secondTestAddedEvent); Reply(TestExecutionResult.SucceededWith(command.SourceId)); } else { TestErrors++; Throw(new TestedErrorEvent(TestErrors)); ReplyFailure(TestExecutionResult.FailedWith(command.SourceId)); } return(true); }
public async Task <Result> Do(CreateAndAddTwoTestsCommand command) { if (IsNew) { var createdEvent = new TestCreatedEvent(command.Id); var firstTestAddedEvent = new TestAddedEvent(command.Id, command.FirstTest); var secondTestAddedEvent = new TestAddedEvent(command.Id, command.SecondTest); await Emit(createdEvent); await Emit(firstTestAddedEvent); await Emit(secondTestAddedEvent); return(Result.Success); } TestErrors++; await Emit(new TestedErrorEvent(Id, TestErrors)); return(Result.Fail("TestedErrorEvent")); }
public void TestEventMultipleEmitSourcing_AfterManyMultiCreateCommand_EventsEmitted() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var firstTest = new TestEntity(TestId.New); var secondTest = new TestEntity(TestId.New); var command = new CreateAndAddTwoTestsCommand(aggregateId, firstTest, secondTest) .WithSourceId(commandId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectDomainEvent <TestCreatedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>(); }
public void TestEventMultipleEmitSourcing_AfterManyMultiCreateCommand_EventsEmitted() { var eventProbe = CreateTestProbe("event-probe"); Sys.EventStream.Subscribe(eventProbe, typeof(IDomainEvent <TestAggregate, TestAggregateId, TestCreatedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(IDomainEvent <TestAggregate, TestAggregateId, TestAddedEvent>)); var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager"); var aggregateId = TestAggregateId.New; var commandId = CommandId.New; var firstTest = new Test(TestId.New); var secondTest = new Test(TestId.New); var command = new CreateAndAddTwoTestsCommand(aggregateId, commandId, firstTest, secondTest); aggregateManager.Tell(command); eventProbe.ExpectMsg <IDomainEvent <TestAggregate, TestAggregateId, TestCreatedEvent> >(); eventProbe.ExpectMsg <IDomainEvent <TestAggregate, TestAggregateId, TestAddedEvent> >(); eventProbe.ExpectMsg <IDomainEvent <TestAggregate, TestAggregateId, TestAddedEvent> >(); }
public void TestEventMultipleEmitSourcing_AfterManyMultiCreateCommand_EventsEmitted() { var eventProbe = CreateTestProbe("event-probe"); Sys.EventStream.Subscribe(eventProbe, typeof(IDomainEvent <TestAggregateId, TestCreatedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(IDomainEvent <TestAggregateId, TestAddedEvent>)); var bus = Sys.GetExtension <ServiceProviderHolder>().ServiceProvider.GetRequiredService <ICommandBus>(); var aggregateId = TestAggregateId.New; var commandId = CommandId.New; var firstTest = new Test(TestId.New); var secondTest = new Test(TestId.New); var command = new CreateAndAddTwoTestsCommand(aggregateId, commandId, firstTest, secondTest); bus.Publish(command).GetAwaiter().GetResult(); eventProbe.ExpectMsg <IDomainEvent <TestAggregateId, TestCreatedEvent> >(); eventProbe.ExpectMsg <IDomainEvent <TestAggregateId, TestAddedEvent> >(); eventProbe.ExpectMsg <IDomainEvent <TestAggregateId, TestAddedEvent> >(); }
private bool Execute(CreateAndAddTwoTestsCommand command) { if (IsNew) { var createdEvent = new TestCreatedEvent(command.AggregateId); var firstTestAddedEvent = new TestAddedEvent(command.FirstTest); var secondTestAddedEvent = new TestAddedEvent(command.SecondTest); var events = Events(createdEvent, firstTestAddedEvent, secondTestAddedEvent); //EmitAll(events, new Metadata {{"some-key","some-value"}}); EmitAll(createdEvent, firstTestAddedEvent, secondTestAddedEvent); Reply(TestExecutionResult.SucceededWith(command.SourceId)); } else { TestErrors++; Throw(new TestedErrorEvent(TestErrors)); ReplyFailure(TestExecutionResult.FailedWith(command.SourceId)); } return(true); }