public async Task should_handle_the_initial_state() { var harness = new InMemoryTestHarness(); _machine = new InvestigationStateMachine(new List <Provider>()); StateMachineSagaTestHarness <Investigation, InvestigationStateMachine> saga = harness.StateMachineSaga <Investigation, InvestigationStateMachine>(_machine); await harness.Start(); var searchRequestedEvent = SearchRequested.Create(new PeopleSearchRequest("test", "test", "test")); try { await harness.InputQueueSendEndpoint.Send(searchRequestedEvent); Assert.IsTrue(harness.Consumed.Select <SearchRequested>().Any(), "Message not received"); Investigation instance = saga.Created.Select(x => x.CorrelationId == searchRequestedEvent.CorrelationId) .FirstOrDefault() ?.Saga; Assert.IsNotNull(instance, "Saga instance not found"); Assert.AreEqual(instance.CurrentState, nameof(_machine.Started)); } finally { await harness.Stop(); } }
public async Task Should_handle_the_stop_state() { var harness = new InMemoryTestHarness(); StateMachineSagaTestHarness <Instance, TestStateMachine> saga = harness.StateMachineSaga <Instance, TestStateMachine>(_machine); var sagaId = Guid.NewGuid(); await harness.Start(); try { await harness.InputQueueSendEndpoint.Send(new Start { CorrelationId = sagaId }); await harness.InputQueueSendEndpoint.Send(new Stop { CorrelationId = sagaId }); Assert.IsTrue(harness.Consumed.Select <Start>().Any(), "Start not received"); Assert.IsTrue(harness.Consumed.Select <Stop>().Any(), "Stop not received"); var instance = saga.Created.ContainsInState(sagaId, _machine, _machine.Final); Assert.IsNotNull(instance, "Saga instance not found"); } finally { await harness.Stop(); } }
public async Task Should_create_a_state_instance() { var harness = new InMemoryTestHarness(); StateMachineSagaTestHarness <OrderState, OrderStateMachine> saga = harness.StateMachineSaga <OrderState, OrderStateMachine>(new OrderStateMachine()); await harness.Start(); try { Guid orderId = NewId.NextGuid(); await harness.Bus.Publish <OrderSubmitted>(new { OrderId = orderId, InVar.Timestamp, CustomerNumber = "12345" }); Guid?instanceId = await saga.Exists(orderId, x => x.Submitted); instanceId.Should().Be(orderId); OrderState instance = saga.Sagas.Contains(instanceId.Value); instance.CustomerNumber.Should().Be("12345"); } finally { await harness.Stop(); } }
public async Task Should_handle_the_initial_state() { var harness = new InMemoryTestHarness(); StateMachineSagaTestHarness <Instance, TestStateMachine> saga = harness.StateMachineSaga <Instance, TestStateMachine>(_machine); Guid sagaId = Guid.NewGuid(); await harness.Start(); try { await harness.InputQueueSendEndpoint.Send(new Start { CorrelationId = sagaId }); Assert.IsTrue(harness.Consumed.Select <Start>().Any(), "Message not received"); Instance instance = saga.Created.Contains(sagaId); Assert.IsNotNull(instance, "Saga instance not found"); Assert.AreEqual(instance.CurrentState, _machine.Running); } finally { await harness.Stop(); } }
public SagaSampleStateMachineTests(DefaultWebHostTestFixture fixture, ITestOutputHelper output) { _testOffset = TimeSpan.Zero; _harness = new InMemoryTestHarness(); _harness.OnConfigureInMemoryBus += ConfigureInMemoryBus; var machine = new SagaSampleStateMachine(); _stateMachineSagaTestHarness = _harness.StateMachineSaga <SagaSampleInstanceState, SagaSampleStateMachine>(machine); _harness.Start().Wait(); fixture.Output = output; _client = fixture.CreateClient(); _fixture = fixture; _output = output; var inputQueueAddress = _harness.InputQueueAddress; var requestClient = _harness.CreateRequestClient <SagaStatusRequestedEvent>(); MockedObjects.SagaStatusRequestClient.Setup(e => e.GetResponse <SagaStatus, SagaStatusNotFound>(It.IsAny <SagaStatusRequestedEvent>(), It.IsAny <CancellationToken>(), It.IsAny <RequestTimeout>())) .Returns((SagaStatusRequestedEvent o, CancellationToken token, RequestTimeout timeout) => { return(requestClient.GetResponse <SagaStatus, SagaStatusNotFound>(o)); }); MockedObjects.IPublishEndpoint.Setup(e => e.Publish(It.IsAny <SagaStartedEvent>(), It.IsAny <CancellationToken>())) .Returns((SagaStartedEvent o, CancellationToken token) => { return(_harness.Bus.Publish(o)); }); }
public async Task Should_not_timeout() { var harness = new InMemoryTestHarness(); var machine = new TestSagaStateMachine(); StateMachineSagaTestHarness <TestSaga, TestSagaStateMachine> sagaHarness = harness.StateMachineSaga <TestSaga, TestSagaStateMachine>(machine); harness.TestTimeout = TimeSpan.FromSeconds(15); harness.OnConfigureBus += x => BusTestFixture.ConfigureBusDiagnostics(x); await harness.Start(); // Act try { IRequestClient <StartCommand> client = harness.CreateRequestClient <StartCommand>(); Response <StartCommandResponse> response = await client.GetResponse <StartCommandResponse>( new { CorrelationId = InVar.Id, }); // Assert // did the actual saga consume the message Assert.True(await sagaHarness.Consumed.Any <StartCommand>()); } finally { await harness.Stop(); } }
public async Task SetUp() { _harness = new InMemoryTestHarness { TestTimeout = TimeSpan.FromSeconds(5) }; _orderStateMachine = new OrderStateMachine(); _saga = _harness.StateMachineSaga <OrderState, OrderStateMachine>(_orderStateMachine); await _harness.Start(); }
public async Task InitializeTestHarness() { _harness = new InMemoryTestHarness(); _machine = new LifeStateMachine(); _sagaHarness = _harness.StateMachineSaga <LifeState, LifeStateMachine>(_machine); // Note: This style can be used in old test environments, where InitializeTestHarness may not be async. //_harness.Start().Wait(); await _harness.Start(); }
public StateMachine_Specs(EventStoreFixture fixture) { _fixture = fixture; _sagaId = Guid.NewGuid(); _harness = new InMemoryTestHarness(); _repository = new EventStoreSagaRepository <Instance>(_fixture.Connection); _machine = new TestStateMachine(); _saga = _harness.StateMachineSaga(_machine, _repository); TaskUtil.Await(StartHarness); }
public StateMachineSpecs(DynamoDbEventStoreFixture fixture) { _knownEventTypes = new KnownEventTypes(); _knownEventTypes.RegisterTypes(typeof(ProcessStarted), typeof(ProcessStopped), typeof(SomeStringAssigned)); _fixture = fixture; _sagaId = Guid.NewGuid(); _harness = new InMemoryTestHarness(); _repository = new DynamoDbSagaRepository <Instance>(_fixture.Connection, _fixture.Options, _knownEventTypes); _machine = new TestStateMachine(); _saga = _harness.StateMachineSaga(_machine, _repository); TaskUtil.Await(StartHarness); }
public async Task Should_respond_to_status_checks() { var harness = new InMemoryTestHarness(); var orderStateMachine = new OrderStateMachine(); StateMachineSagaTestHarness <OrderState, OrderStateMachine> saga = harness.StateMachineSaga <OrderState, OrderStateMachine>(orderStateMachine); await harness.Start(); try { Guid orderId = NewId.NextGuid(); await harness.Bus.Publish <OrderSubmitted>(new { OrderId = orderId, InVar.Timestamp, CustomerNumber = "12345" }); Guid?instanceId = await saga.Exists(orderId, x => x.Submitted); instanceId.Should().Be(orderId); var requestClient = await harness.ConnectRequestClient <CheckOrder>(); var response = await requestClient.GetResponse <OrderStatus>(new { OrderId = orderId }); response.Message.State.Should().Be(orderStateMachine.Submitted.Name); } finally { await harness.Stop(); } }