TestableSaga throws exception when handler has MarkAsComplete()

I’m testing my saga’s with TestableMessageHandlerContext and TestableSaga (v7.4.0).

I have a test to test the message that starts the saga, like:

var testableSaga = new TestableSaga<SyncContactWorkflow, SagaSyncContactWorkflow>(() =>
            new SyncContactWorkflow(testContext.GetLogger<SyncContactWorkflow>(), Substitute.For<IDistributedConfiguration>(), testContext.Mapper));
        
// act
var result = await testableSaga.Handle(purgedContactUpdated, new TestableMessageHandlerContext());

This works ok, until I add MarkAsComplete() in the handler. Then it throws the exception below. Am I doing something wrong or is this a bug in the TestableSaga or TestableMessageHandlerContext?

System.Exception: The saga should be retrieved with Get method before it's updated

System.Exception
The saga should be retrieved with Get method before it's updated
   at NServiceBus.Testing.NonDurableSagaPersister.GetEntry(ReadOnlyContextBag context, Guid sagaDataId) in D:\a\NServiceBus.Testing\NServiceBus.Testing\src\NServiceBus.Testing\Sagas\NonDurableStorage\NonDurableSagaPersister.cs:line 132
   at NServiceBus.Testing.NonDurableSagaPersister.<>c__DisplayClass1_0.<Complete>b__0() in D:\a\NServiceBus.Testing\NServiceBus.Testing\src\NServiceBus.Testing\Sagas\NonDurableStorage\NonDurableSagaPersister.cs:line 28
   at NServiceBus.NonDurableTransaction.Commit() in D:\a\NServiceBus.Testing\NServiceBus.Testing\src\NServiceBus.Testing\Sagas\NonDurableStorage\NonDurableTransaction.cs:line 15
   at NServiceBus.Testing.NonDurableSynchronizedStorageSession.CompleteAsync() in D:\a\NServiceBus.Testing\NServiceBus.Testing\src\NServiceBus.Testing\Sagas\NonDurableStorage\NonDurableSynchronizedStorageSession.cs:line 32
   at NServiceBus.Testing.TestableSaga`2.InnerHandle(QueuedSagaMessage message, String handleMethodName, TestableMessageHandlerContext context) in D:\a\NServiceBus.Testing\NServiceBus.Testing\src\NServiceBus.Testing\Sagas\TestableSaga.cs:line 221
   at AV.SpotlerAutomate.Tests.SyncContactWorkflowGivenContactUpdatedEvent.Step1_IgnoreMessage_GivenContactUpdatedAfterPurged() in

@remyvd,

I think you’re facing this issue. Can you confirm it’s the same scenario?

.m

Yes, it is the same issue. Looked at the test of the fix and seems to be equal to my case.

Thanks @mauroservienti

@remyvd the fix has been released in 7.4.1, see the announcement for more detals.

Upgraded and it works! Thanks!