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(); } }
private static void ConfigureServiceBus(IServiceCollection services, IConfiguration configuration) { var rabbitMqSettings = configuration.GetSection(nameof(RabbitMq)).Get <RabbitMq>(); var rabbitBaseUri = $"amqp://{rabbitMqSettings.Host}:{rabbitMqSettings.Port}"; var factory = new Factory(); ISagaDbContextFactory <Investigation> contextFactory = new DelegateSagaDbContextFactory <Investigation>(() => factory.CreateDbContext(Array.Empty <string>())); var repository = new EntityFrameworkSagaRepository <Investigation>(contextFactory); // Register Mass Transit services.AddMassTransit(x => { // Add RabbitMq Service Bus x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg => { var investigationStateMachine = new InvestigationStateMachine(configuration.GetSection("providers").Get <List <Provider> >()); var host = cfg.Host(new Uri(rabbitBaseUri), hostConfigurator => { hostConfigurator.Username(rabbitMqSettings.Username); hostConfigurator.Password(rabbitMqSettings.Password); }); cfg.ReceiveEndpoint(host, "investigation_state", e => { e.StateMachineSaga(investigationStateMachine, repository); }); })); }); }