public async Task WHEN_eventIsSend_THEN_sagaShouldMoveToValidState() { // given ISaga saga = await sagaCoordinator. Publish(new SendCreateEvent()); // when await sagaCoordinator. Publish(new TestSendActionEvent() { ID = saga.Data.ID }); // then ISaga orgSaga = await sagaPersistance. Get(saga.Data.ID); SendTestsData data = orgSaga.Data as SendTestsData; ISaga createdSaga = await sagaPersistance. Get(data.CreatedSagaID); orgSaga.ShouldNotBeNull(); orgSaga.ExecutionState.CurrentState.ShouldBe(nameof(AfterInit)); orgSaga.ExecutionState.CurrentStep.ShouldBe(null); createdSaga.ShouldNotBeNull(); createdSaga.ExecutionState.CurrentState.ShouldBe(nameof(AkternativeInit)); createdSaga.ExecutionState.CurrentStep.ShouldBe(null); }
public async Task WHEN_sendValidStateToSagaWithError_THEN_errorShouldBeNull() { // given ISaga saga = await sagaCoordinator. Publish(new ValidCreatedEvent()); await Assert.ThrowsAsync <TestCompensationException>(async() => { await sagaCoordinator.Publish(new InvalidCompensationEvent() { ID = saga.Data.ID }); }); // when await sagaCoordinator.Publish(new ValidUpdateEvent() { ID = saga.Data.ID }); // then ISaga persistedSaga = await sagaPersistance. Get(saga.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentStep.ShouldBe(null); persistedSaga.ExecutionState.CurrentState.ShouldBe(nameof(StateUpdated)); persistedSaga.ExecutionState.CurrentError.ShouldBeNull(); persistedSaga.Data.ID.ShouldBe(saga.Data.ID); }
public async Task WHEN_compensationThrowsErrorOnUpdate_THEN_sagaShouldBeInValidState() { // given ISaga saga = await sagaCoordinator. Publish(new ValidCreatedEvent()); // when await Assert.ThrowsAsync <TestCompensationException>(async() => { await sagaCoordinator.Publish(new InvalidCompensationEvent() { ID = saga.Data.ID }); }); // then ISaga persistedSaga = await sagaPersistance. Get(saga.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentStep.ShouldBe(null); persistedSaga.ExecutionState.CurrentState.ShouldBe(nameof(StateCreated)); persistedSaga.ExecutionState.CurrentError.ShouldNotBeNull(); persistedSaga.Data.ID.ShouldBe(saga.Data.ID); persistedSaga.ExecutionState.History.ShouldContain(item => item.CompensationData != null && item.StepName == "InvalidCompensationEventStep1"); persistedSaga.ExecutionState.History.ShouldContain(item => item.CompensationData != null && item.StepName == "InvalidCompensationEventStep2"); persistedSaga.ExecutionState.History.ShouldContain(item => item.CompensationData != null && item.StepName == "InvalidCompensationEventStep3"); }
public async Task WHEN_someNextEvent_THEN_sagaShouldBeInValidState() { // given ISaga newSagaState = await sagaCoordinator. Publish(new OrderCreatedEvent()); ISagaEvent skompletowanoEvent = new OrderCompletedEvent() { ID = newSagaState.Data.ID }; // then await sagaCoordinator. Publish(skompletowanoEvent); // then ISaga persistedSaga = await sagaPersistance. Get(newSagaState.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentState.ShouldBe(nameof(StateCompleted)); persistedSaga.ExecutionState.CurrentStep.ShouldBe(null); persistedSaga.ExecutionState.History.ShouldNotContain(step => step.StepName == "OrderCreatedEventStep0" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.ShouldNotContain(step => step.StepName == "OrderCreatedEventStep1" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "OrderCompletedEventStep1" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "email" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "SendMessageToTheManagerEventStep" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "OrderCourierEventStep" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.Count.ShouldBe(6); }
public async Task WHEN_invalidEvent_THEN_sagaShouldIgnoreThatEvent() { // given ISaga newSagaState = await sagaCoordinator. Publish(new OrderCreatedEvent()); ISagaEvent invalidEvent = new OrderSendEvent() { ID = newSagaState.Data.ID }; // then await Assert.ThrowsAsync <SagaInvalidEventForStateException>(() => // when sagaCoordinator. Publish(invalidEvent) ); // then ISaga persistedSaga = await sagaPersistance. Get(newSagaState.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentState.ShouldBe(nameof(StateCreated)); persistedSaga.ExecutionState.CurrentStep.ShouldBe(null); // blad nie powinien zmienic stanu sagi persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "OrderCreatedEventStep1" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.Count.ShouldBe(3); }
public async Task WHEN_afterAsynchronousSagaRun_THEN_sagaShouldBeCompleted() { // given ISagaEvent startEvent = new CreatedEvent(); ISaga saga = await sagaCoordinator. Publish(startEvent); // when await sagaCoordinator. WaitForIdle(saga.Data.ID); // then ISaga persistedSaga = await sagaPersistance. Get(saga.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentStep.ShouldBe(new SagaFinishState().Name); persistedSaga.ExecutionState.CurrentState.ShouldBe(new SagaFinishState().Name); persistedSaga.Data.ID.ShouldBe(saga.Data.ID); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "CreatedEventStep0" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "CreatedEventStep1" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "CreatedEventStep2" && step.CompensationData == null && step.HasSucceeded()); persistedSaga.ExecutionState.History.Count.ShouldBe(4); }
public async Task WHEN_startEvent_THEN_sagaShouldBeCreated() { // given ISagaEvent startEvent = new OrderCreatedEvent(); // when ISaga saga = await sagaCoordinator. Publish(startEvent); // then ISaga persistedSaga = await sagaPersistance. Get(saga.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentStep.ShouldBe(null); persistedSaga.ExecutionState.CurrentState.ShouldBe(nameof(StateCreated)); persistedSaga.Data.ID.ShouldBe(saga.Data.ID); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "OrderCreatedEventStep1" && step.CompensationData == null && step.HasSucceeded()); }
public async Task WHEN_runSagaAsynchronous_THEN_sagaShouldBeInIntermediateState() { // given ISagaEvent startEvent = new CreatedEvent(); // when ISaga saga = await sagaCoordinator. Publish(startEvent); // then ISaga persistedSaga = await sagaPersistance. Get(saga.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentStep.ShouldStartWith("CreatedEventStep"); persistedSaga.ExecutionState.CurrentState.ShouldBe(new SagaStartState().Name); persistedSaga.Data.ID.ShouldBe(saga.Data.ID); persistedSaga.ExecutionState.History.ShouldContain(step => step.StepName == "CreatedEventStep0" && step.CompensationData == null); }
public async Task WHEN_otherEventIsSend_THEN_sagaShouldMoveToOtherValidState() { // given ISaga saga = await sagaCoordinator. Publish(new OrderCreatedEvent()); // when await sagaCoordinator. Publish(new ToAlternative2Event() { ID = saga.Data.ID }); // then ISaga persistedSaga = await sagaPersistance. Get(saga.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentStep.ShouldBe(null); persistedSaga.ExecutionState.CurrentState.ShouldBe(nameof(StateAlternative2)); persistedSaga.Data.ID.ShouldBe(saga.Data.ID); }
public async Task WHEN_eventIsSend_THEN_sagaShouldMoveToValidState() { // given ISaga saga = await sagaCoordinator. Publish(new CreateEvent()); // when await Assert.ThrowsAsync <Exception>(() => sagaCoordinator. Publish(new InvalidUpdateEvent() { ID = saga.Data.ID })); // then ISaga persistedSaga = await sagaPersistance. Get(saga.Data.ID); persistedSaga.ShouldNotBeNull(); persistedSaga.ExecutionState.CurrentStep.ShouldBe(null); persistedSaga.ExecutionState.CurrentState.ShouldBe(nameof(Init)); persistedSaga.Data.ID.ShouldBe(saga.Data.ID); }