Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

860
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda