I am in the process of writing some unit tests for my Rebus Handlers. I have opted to enable secondLevelRetriesEnabled which results in an IFailed<TMessage> being published when an exception is thrown in the Handler.
My Handler class definition is:
Handler<T> : IHandleMessages<T>, IHandleMessages<IFailed<T>>
When I run the process everything works as expected; the difficulty comes when attempting to write a unit test for the secondLevelRetriesEnabled behaviour.
When my unit test calls the IFailed<TMessage> method of my Handler which results in a call to await bus.Advanced.TransportMessage.Deadletter(message) I get the following exception from the FakeBus.
"Attempted to dead-letter the current message using error details 'Failed to handle message after 2 deferrals', but no message context could be found! This is probably a sign that this method was called OUTSIDE of a Rebus handler, or on a separate, disconnected thread somehow. Please only call this method inside Rebus handlers."
Can someone point me in the right direction to resolve the Deadletter queue exception when testing the IFailed message handle. As far as I can see there is no HandleFixture like the SagaFixture which supports fixture.DeliverFailed(new OrdinaryMessage(...), new ApplicationException("oh no"));