Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

863
Visualizações
How to seed initial state to a saga in MassTransit test harness?

In previous versions of MassTransit, when writing unit tests, I used to seed initial state of a saga by calling the InMemorySagaRepository.Add() method:

private InMemorySagaRepository<TState> Repository { get; }

protected async Task SeedSaga<TState>(TState seedState)
    where TState : class, SagaStateMachineInstance
{
    await Repository.Add(new SagaInstance<TState>(seedState), default);
}

This method would add an entry for the saga in the desired state in the repository, which could be used as a starting point for my tests.

Now I upgraded to the version 7.2.1 of MassTransit and this method is no longer available.

Is it possible to seed data in the current version of the InMemorySagaRepository? If not, what approach could be taken to achive similar results?

Thanks.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There was a discussion on this late last year. In summary, you need to be using the container-based in-memory test harness.

var services = new ServiceCollection();
services.AddMassTransitInMemoryTestHarness(x => 
{
    x.AddSagaStateMachineTestHarness<MySagaStateMachine, MySagaState>();
    x.AddSagaStateMachine<MySagaStateMachine, MySagaState>()
        .InMemoryRepository();
});
var provider = services.BuildServiceProvider();

Get and start the test harness (be sure to stop it in finally):

var harness = provider.GetRequiredService<InMemoryTestHarness>();
await harness.Start();

You can obtain the saga dictionary and add your seeded saga instance:

var dictionary = provider.GetRequiredService<IndexedSagaDictionary<MySagaState>>();
dictionary.Add(new SagaInstance(new MySagaState 
{ 
    CorrelationId = ...,
    OtherProperty = ...
}));

The linked discussion has some useful extension methods as well.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda