public void TestCommandTwice_AfterAggregateCreation_TestEventEmitted() { var probe = CreateTestActor("probeActor"); Sys.EventStream.Subscribe(probe, typeof(DomainEvent <TestAggregate, TestAggregateId, TestAddedEvent>)); var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager"); var aggregateId = TestAggregateId.New; var command = new CreateTestCommand(aggregateId); var testId = TestId.New; var test = new Test(testId); var nextCommand = new AddTestCommand(aggregateId, test); var test2Id = TestId.New; var test2 = new Test(test2Id); var nextCommand2 = new AddTestCommand(aggregateId, test2); aggregateManager.Tell(command); aggregateManager.Tell(nextCommand); aggregateManager.Tell(nextCommand2); ExpectMsg <DomainEvent <TestAggregate, TestAggregateId, TestAddedEvent> >( x => x.AggregateEvent.Test.Equals(test) && x.AggregateSequenceNumber == 2); ExpectMsg <DomainEvent <TestAggregate, TestAggregateId, TestAddedEvent> >( x => x.AggregateEvent.Test.Equals(test2) && x.AggregateSequenceNumber == 3); }
public void TestEventSourcing_AfterManyTests_TestStateSignalled() { var probe = CreateTestActor("probe"); Sys.EventStream.Subscribe(probe, typeof(DomainEvent <TestAggregate, TestAggregateId, TestStateSignalEvent>)); var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager"); var aggregateId = TestAggregateId.New; var command = new CreateTestCommand(aggregateId); aggregateManager.Tell(command); for (var i = 0; i < 5; i++) { var test = new Test(TestId.New); var testCommand = new AddTestCommand(aggregateId, test); aggregateManager.Tell(testCommand); } var poisonCommand = new PoisonTestAggregateCommand(aggregateId); aggregateManager.Tell(poisonCommand); var reviveCommand = new PublishTestStateCommand(aggregateId); aggregateManager.Tell(reviveCommand); ExpectMsg <DomainEvent <TestAggregate, TestAggregateId, TestStateSignalEvent> >( x => x.AggregateEvent.LastSequenceNr == 6 && x.AggregateEvent.Version == 6 && x.AggregateEvent.AggregateState.TestCollection.Count == 5); }
public void TestSnapShotting_AfterManyTests_TestStateSignalled() { var eventProbe = CreateTestProbe("event-probe"); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestAggregate, TestAggregateId, TestStateSignalEvent>)); var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager"); var aggregateId = TestAggregateId.New; var commandId = CommandId.New; var command = new CreateTestCommand(aggregateId, commandId); aggregateManager.Tell(command); for (var i = 0; i < 10; i++) { var test = new Test(TestId.New); var testCommandId = CommandId.New; var testCommand = new AddTestCommand(aggregateId, testCommandId, test); aggregateManager.Tell(testCommand); } eventProbe .ExpectMsg <DomainEvent <TestAggregate, TestAggregateId, TestStateSignalEvent> >( x => x.AggregateEvent.LastSequenceNr == 11 && x.AggregateEvent.Version == 11 && x.AggregateEvent.AggregateState.TestCollection.Count == 10 && x.AggregateEvent.AggregateState.FromHydration); }
public void TestSnapShotting_AfterManyTests_TestStateSignalled() { var eventProbe = CreateTestProbe("event-probe"); Sys.EventStream.Subscribe(eventProbe, typeof(IDomainEvent <TestAggregateId, TestStateSignalEvent>)); var aggregateId = TestAggregateId.New; var commandId = CommandId.New; var bus = Sys.GetExtension <ServiceProviderHolder>().ServiceProvider.GetRequiredService <ICommandBus>(); var command = new CreateTestCommand(aggregateId, commandId); bus.Publish(command).GetAwaiter().GetResult(); for (var i = 0; i < 10; i++) { var test = new Test(TestId.New); var testCommandId = CommandId.New; var testCommand = new AddTestCommand(aggregateId, testCommandId, test); bus.Publish(testCommand).GetAwaiter().GetResult(); } eventProbe.ExpectMsg <IDomainEvent <TestAggregateId, TestStateSignalEvent> >( x => x.AggregateEvent.LastSequenceNr == 11 && x.AggregateEvent.Version == 11 && x.AggregateEvent.AggregateState.TestCollection.Count == 10 && x.AggregateEvent.AggregateState.FromHydration); }
public void TestCommandTwice_AfterAggregateCreation_TestEventEmitted() { var eventProbe = CreateTestProbe("event-probe"); 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 command = new CreateTestCommand(aggregateId, commandId); var testId = TestId.New; var test = new Test(testId); var nextCommandId = CommandId.New; var nextCommand = new AddTestCommand(aggregateId, nextCommandId, test); var test2Id = TestId.New; var test2 = new Test(test2Id); var nextCommandId2 = CommandId.New; var nextCommand2 = new AddTestCommand(aggregateId, nextCommandId2, test2); bus.Publish(command).GetAwaiter().GetResult(); bus.Publish(nextCommand).GetAwaiter().GetResult(); bus.Publish(nextCommand2).GetAwaiter().GetResult(); eventProbe.ExpectMsg <IDomainEvent <TestAggregateId, TestAddedEvent> >(x => x.AggregateEvent.Test.Equals(test) && x.AggregateSequenceNumber == 2); eventProbe.ExpectMsg <IDomainEvent <TestAggregateId, TestAddedEvent> >(x => x.AggregateEvent.Test.Equals(test2) && x.AggregateSequenceNumber == 3); }
public void TestCommandTwice_AfterAggregateCreation_TestEventEmitted() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new CreateTestCommand(aggregateId).WithSourceId(commandId); var testId = TestId.New; var test = new TestEntity(testId); var nextCommandId = SourceId.New; var nextCommand = new AddTestCommand(aggregateId, test).WithSourceId(nextCommandId); var test2Id = TestId.New; var test2 = new TestEntity(test2Id); var nextCommandId2 = SourceId.New; var nextCommand2 = new AddTestCommand(aggregateId, test2).WithSourceId(nextCommandId2); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command, nextCommand, nextCommand2) .ThenExpectDomainEvent <TestCreatedEvent>() .ThenExpectDomainEvent <TestAddedEvent>( x => x.AggregateEvent.Test.Equals(test)) .ThenExpectDomainEvent <TestAddedEvent>( x => x.AggregateEvent.Test.Equals(test2)); }
public void SendingTest_FromTestAggregate_CompletesSaga() { var eventProbe = CreateTestProbe("event-probe"); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSaga, TestSagaId, TestSagaStartedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSaga, TestSagaId, TestSagaCompletedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSaga, TestSagaId, TestSagaTransactionCompletedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSaga, TestSagaId, TestSagaTimeoutOccurred>)); var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager"); Sys.ActorOf(Props.Create(() => new TestSagaManager(() => new TestSaga(aggregateManager))), "test-sagaaggregatemanager"); var senderAggregateId = TestAggregateId.New; var senderCreateAggregateCommand = new CreateTestCommand(senderAggregateId, CommandId.New); aggregateManager.Tell(senderCreateAggregateCommand); var receiverAggregateId = TestAggregateId.New; var receiverCreateAggregateCommand = new CreateTestCommand(receiverAggregateId, CommandId.New); aggregateManager.Tell(receiverCreateAggregateCommand); var senderTestId = TestId.New; var senderTest = new Test(senderTestId); var nextAggregateCommand = new AddTestCommand(senderAggregateId, CommandId.New, senderTest); aggregateManager.Tell(nextAggregateCommand); var sagaStartingCommand = new GiveTestCommand(senderAggregateId, CommandId.New, receiverAggregateId, senderTest); aggregateManager.Tell(sagaStartingCommand); eventProbe. ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaStartedEvent> >( x => x.AggregateEvent.Sender.Equals(senderAggregateId) && x.AggregateEvent.Receiver.Equals(receiverAggregateId) && x.AggregateEvent.SentTest.Equals(senderTest), new TimeSpan(0, 0, 20)); eventProbe. ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaTransactionCompletedEvent> >(new TimeSpan(0, 0, 20)); eventProbe. ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaCompletedEvent> >(new TimeSpan(0, 0, 20)); eventProbe.ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaTimeoutOccurred> >( timeoutMsg => timeoutMsg.AggregateEvent.TimeoutMessage.Equals("First timeout test"), TimeSpan.FromSeconds(15)); eventProbe.ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaTimeoutOccurred> >( timeoutMsg => timeoutMsg.AggregateEvent.TimeoutMessage.StartsWith("Second timeout test"), TimeSpan.FromSeconds(15)); }
private bool Execute(AddTestCommand command) { if (!IsNew) { Emit(new TestAddedEvent(command.Test)); } else { TestErrors++; Throw(new TestedErrorEvent(TestErrors)); } return(true); }
public async Task <Result> Do(AddTestCommand command) { if (!IsNew) { await Emit(new TestAddedEvent(Id, command.Test)); return(Result.Success); } TestErrors++; await Emit(new TestedErrorEvent(Id, TestErrors)); return(Result.Fail("TestedErrorEvent")); }
private bool Execute(AddTestCommand command) { if (!IsNew) { Emit(new TestAddedEvent(command.Test)); Reply(TestExecutionResult.SucceededWith(command.SourceId)); } else { TestErrors++; Throw(new TestedErrorEvent(TestErrors)); Reply(TestExecutionResult.FailedWith(command.SourceId)); } return(true); }
public Task <IExecutionResult> Execute(AddTestCommand command) { if (!IsNew) { Emit(new TestAddedEvent(command.Test)); Reply(TestExecutionResult.SucceededWith(command.Metadata.SourceId)); } else { TestErrors++; Throw(new TestedErrorEvent(TestErrors)); ReplyFailure(TestExecutionResult.FailedWith(command.Metadata.SourceId)); } return(Task.FromResult((IExecutionResult) new SuccessTestExecutionResult(command.Metadata.SourceId))); }
public void SendingTest_FromTestAggregate_CompletesSagaAsync() { var eventProbe = CreateTestProbe("event-probe"); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestAsyncSaga, TestAsyncSagaId, TestAsyncSagaStartedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestAsyncSaga, TestAsyncSagaId, TestAsyncSagaCompletedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestAsyncSaga, TestAsyncSagaId, TestAsyncSagaTransactionCompletedEvent>)); var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager"); Sys.ActorOf(Props.Create(() => new TestAsyncSagaManager(() => new TestAsyncSaga(aggregateManager))), "test-sagaaggregatemanager"); var senderAggregateId = TestAggregateId.New; var senderCreateAggregateCommand = new CreateTestCommand(senderAggregateId, CommandId.New); aggregateManager.Tell(senderCreateAggregateCommand); var receiverAggregateId = TestAggregateId.New; var receiverCreateAggregateCommand = new CreateTestCommand(receiverAggregateId, CommandId.New); aggregateManager.Tell(receiverCreateAggregateCommand); var senderTestId = TestId.New; var senderTest = new Test(senderTestId); var nextAggregateCommand = new AddTestCommand(senderAggregateId, CommandId.New, senderTest); aggregateManager.Tell(nextAggregateCommand); var sagaStartingCommand = new GiveTestCommand(senderAggregateId, CommandId.New, receiverAggregateId, senderTest); aggregateManager.Tell(sagaStartingCommand); eventProbe. ExpectMsg <DomainEvent <TestAsyncSaga, TestAsyncSagaId, TestAsyncSagaStartedEvent> >( x => x.AggregateEvent.Sender.Equals(senderAggregateId) && x.AggregateEvent.Receiver.Equals(receiverAggregateId) && x.AggregateEvent.SentTest.Equals(senderTest) && x.Metadata.ContainsKey("some-key")); eventProbe. ExpectMsg <DomainEvent <TestAsyncSaga, TestAsyncSagaId, TestAsyncSagaTransactionCompletedEvent> >(); eventProbe. ExpectMsg <DomainEvent <TestAsyncSaga, TestAsyncSagaId, TestAsyncSagaCompletedEvent> >(); }
public void SendingTest_FromTestAggregate_CompletesSaga() { var eventProbe = CreateTestProbe("event-probe"); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSagaId, TestSagaStartedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSagaId, TestSagaCompletedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSagaId, TestSagaTransactionCompletedEvent>)); var bus = Sys.GetExtension <ServiceProviderHolder>().ServiceProvider.GetRequiredService <ICommandBus>(); var senderAggregateId = TestAggregateId.New; var senderCreateAggregateCommand = new CreateTestCommand(senderAggregateId, CommandId.New); bus.Publish(senderCreateAggregateCommand).GetAwaiter().GetResult(); var receiverAggregateId = TestAggregateId.New; var receiverCreateAggregateCommand = new CreateTestCommand(receiverAggregateId, CommandId.New); bus.Publish(receiverCreateAggregateCommand).GetAwaiter().GetResult(); var senderTestId = TestId.New; var senderTest = new Test(senderTestId); var nextAggregateCommand = new AddTestCommand(senderAggregateId, CommandId.New, senderTest); bus.Publish(nextAggregateCommand).GetAwaiter().GetResult(); var sagaStartingCommand = new GiveTestCommand(senderAggregateId, CommandId.New, receiverAggregateId, senderTest); bus.Publish(sagaStartingCommand).GetAwaiter().GetResult(); eventProbe.ExpectMsg <DomainEvent <TestSagaId, TestSagaStartedEvent> >( x => x.AggregateEvent.Sender.Equals(senderAggregateId) && x.AggregateEvent.Receiver.Equals(receiverAggregateId) && x.AggregateEvent.SentTest.Equals(senderTest)); eventProbe.ExpectMsg <DomainEvent <TestSagaId, TestSagaTransactionCompletedEvent> >(); eventProbe.ExpectMsg <DomainEvent <TestSagaId, TestSagaCompletedEvent> >(); }
public void TestEventSourcing_AfterManyTests_TestStateSignalled() { IEnumerable <ICommand> GetCommands(TestAggregateId testAggregateId, ISourceId commandId1) { var command = new CreateTestCommand(testAggregateId).WithSourceId(commandId1); yield return(command); for (var i = 0; i < 5; i++) { var test = new TestEntity(TestId.New); var testCommandId = SourceId.New; var testCommand = new AddTestCommand(testAggregateId, test).WithSourceId(testCommandId); yield return(testCommand); } var poisonCommand = new PoisonTestAggregateCommand(testAggregateId); yield return(poisonCommand); } var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(GetCommands(aggregateId, commandId).ToArray()) .ThenExpectDomainEvent <TestCreatedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectState( x => x.TestCollection.Count == 5); }
public void TestCommand_AfterAggregateCreation_TestEventEmitted() { var eventProbe = CreateTestProbe("event-probe"); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestAggregate, TestAggregateId, TestAddedEvent>)); var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager"); var aggregateId = TestAggregateId.New; var commandId = CommandId.New; var command = new CreateTestCommand(aggregateId, commandId); var testId = TestId.New; var test = new Test(testId); var nextCommandId = CommandId.New; var nextCommand = new AddTestCommand(aggregateId, nextCommandId, test); aggregateManager.Tell(command); aggregateManager.Tell(nextCommand); eventProbe .ExpectMsg <DomainEvent <TestAggregate, TestAggregateId, TestAddedEvent> >( x => x.AggregateEvent.Test.Equals(test)); }
public void SendingTest_FromTestAggregate_CompletesSaga() { var probe = CreateTestActor("probeActor"); Sys.EventStream.Subscribe(probe, typeof(DomainEvent <TestSaga, TestSagaId, TestSagaStartedEvent>)); var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager"); Sys.ActorOf(Props.Create(() => new TestSagaManager(() => new TestSaga(aggregateManager))), "test-sagaaggregatemanager"); var senderAggregateId = TestAggregateId.New; var senderCreateAggregateCommand = new CreateTestCommand(senderAggregateId, probe); aggregateManager.Tell(senderCreateAggregateCommand); var receiverAggregateId = TestAggregateId.New; var receiverCreateAggregateCommand = new CreateTestCommand(receiverAggregateId, probe); aggregateManager.Tell(receiverCreateAggregateCommand); var senderTestId = TestId.New; var senderTest = new Test(senderTestId); var nextAggregateCommand = new AddTestCommand(senderAggregateId, senderTest); aggregateManager.Tell(nextAggregateCommand); var sagaStartingCommand = new GiveTestCommand(senderAggregateId, receiverAggregateId, senderTest); aggregateManager.Tell(sagaStartingCommand); ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaStartedEvent> >( x => x.AggregateEvent.Sender.Equals(senderAggregateId) && x.AggregateEvent.Receiver.Equals(receiverAggregateId) && x.AggregateEvent.SentTest.Equals(senderTest)); }
public void Aggregates_can_be_hydrated() { var senderTestId = TestId.NewDeterministic(TestIdNamespace, (DateTime.UtcNow.Day - 1).ToString()); var senderTest = new Test(senderTestId); var receiver = TestAggregateId.NewDeterministic(TestIdNamespace, (DateTime.UtcNow.Day + 1).ToString()); var sender = TestAggregateId.NewDeterministic(TestIdNamespace, DateTime.UtcNow.Day.ToString()); RunOn(() => { //set up event probe // set up sender var senderProbe = CreateTestProbe("sender-probe"); var commandId = CommandId.New; _aggregateProxy.Value.Tell(new CreateTestCommand(sender, commandId), senderProbe); senderProbe.ExpectMsg <TestExecutionResult>( x => x.Result.IsSuccess && x.SourceId.Value == commandId.Value, TimeSpan.FromSeconds(10)); var nextAggregateCommand = new AddTestCommand(sender, CommandId.New, senderTest); _aggregateProxy.Value.Tell(nextAggregateCommand, senderProbe); senderProbe.ExpectMsg <TestExecutionResult>( x => x.Result.IsSuccess, TimeSpan.FromSeconds(10)); // set up receiver var receiverProbe = CreateTestProbe("receiver-probe"); var commandId2 = CommandId.New; _aggregateProxy.Value.Tell(new CreateTestCommand(receiver, commandId2), receiverProbe); receiverProbe.ExpectMsg <TestExecutionResult>( x => x.Result.IsSuccess && x.SourceId.Value == commandId2.Value, TimeSpan.FromSeconds(10)); }, _config.Client); EnterBarrier("aggregates-hydrated"); var eventProbe = CreateTestProbe("event-probe"); RunOn(() => { Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSaga, TestSagaId, TestSagaStartedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSaga, TestSagaId, TestSagaCompletedEvent>)); Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestSaga, TestSagaId, TestSagaTransactionCompletedEvent>)); }, _config.Worker); RunOn(() => { var senderProbe = CreateTestProbe("saga-starting-probe"); var nextAggregateCommand = new GiveTestCommand(sender, CommandId.New, receiver, senderTest); _aggregateProxy.Value.Tell(nextAggregateCommand, senderProbe); senderProbe.ExpectMsg <TestExecutionResult>( x => x.Result.IsSuccess, TimeSpan.FromSeconds(10)); }, _config.Client); RunOn(() => { eventProbe. ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaStartedEvent> >( x => x.AggregateEvent.Sender.Equals(sender) && x.AggregateEvent.Receiver.Equals(receiver) && x.AggregateEvent.SentTest.Equals(senderTest), TimeSpan.FromSeconds(20)); eventProbe. ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaTransactionCompletedEvent> >(TimeSpan.FromSeconds(20)); eventProbe. ExpectMsg <DomainEvent <TestSaga, TestSagaId, TestSagaCompletedEvent> >(TimeSpan.FromSeconds(20)); }, _config.Worker); EnterBarrier("saga-finished"); }
public async Task <IActionResult> AddTest(AddTestCommand command) { return(Ok(await Mediator.Send(command))); }