I appreciate this is not the intended use of this framework and it is internal. I’m using the NServicebus.AcceptanceTesting framework to create an integration test suite. I have a couple of EndpointConfigurationBuilders and I’m using message mutators to record in the scenario context which messages are received and sent. However I have an issue when I add this mutator, the message is received, processed and the scenario context updated, however the message is received multiple times, assume because its failing and the test eventually fails with the following error “Some failed messages were not handled by the recoverability feature”. I’ve struggled to identify why this is happening and this is why I’m reaching out to yourselves.
[TestMethod]
public async Task When_RegistrationAccepted_is_recieved()
{
var testContext =
await Scenario.Define<SagaContext>()
.WithEndpoint<Endpoints.SendingEndpoint>(b => b.CustomConfig(c =>
{
c.OnEndpointSubscribed<SagaContext>(
(s, ctx) => ctx.RegistrationAcceptedSubscriptionReceived = true);
})
.When(c => c.RegistrationAcceptedSubscriptionReceived,
(session, c) => session.Publish(new RegistrationAccepted
{
Reg_ID = "1900060609789"
}))
)
.WithEndpoint<RecieverEndpoint>(
b => b.When(async (session, c) =>
{
await session.Subscribe<RegistrationAccepted>();
if (c.HasNativePubSubSupport)
{
c.RegistrationAcceptedSubscriptionReceived = true;
}
}))
.Done(c => c.RegistrationAcceptedSubscriptionReceived
&& c.RegistrationAcceptedRecieved)
.Run();
}
public class SagaInspector : IMutateIncomingMessages, IMutateOutgoingMessages, INeedInitialization
{
public SagaContext Context { get; set; }
public Task MutateOutgoing(MutateOutgoingMessageContext context)
{
return Task.FromResult(context);
}
public void Customize(EndpointConfiguration configuration)
{
configuration.RegisterComponents(c => c.ConfigureComponent<SagaInspector>(DependencyLifecycle.InstancePerCall));
}
public Task MutateIncoming(MutateIncomingMessageContext context)
{
if (context.Message is RegistrationAccepted)
Context.RegistrationAcceptedRecieved = true;
return Task.FromResult(context);
}
}