Closed andrescardenash closed 3 months ago
Hi @andrescardenash , sorry for taking so long to get back to you.
Your problem is valid, ~but there's no built-in way in Rebus to fake the current message context. It's available via the static Current
property on MessageContext
, but it's actually instantiated every time it gets requested from the current ambient transaction context, IF the ambient transaction context~ and I just figured out how easy it was for me to help you š
With Rebus.TestHelpers 9.1.0 (which is on NuGet.org now!) you can do this:
var transportMessage = new TransportMessage(headers, body);
using var scope = new FakeMessageContextScope(transportMessage);
// this will now be available š
var messageContext = MessageContext.Current;
It should make it very easy for you (and anyone else with similar problems) to write proper unit tests of their pipeline steps.
Thanks for directing my attention to the fact that this was missing.
Thank you so much!!
I'm facing a challenge with mocking
MessageContext.Current
in an outgoing step in Rebus. I have a piece of code that looks like this:I've tried to follow the steps to create tests for incoming and outgoing steps(link), but I'm still unable to mock MessageContext.Current successfully. Can you provide guidance or examples on how to properly mock MessageContext.Current in this context? the idea is to create a test to validate some additional headers that InsertDistributedTraceHeaders is appending but MessageContentext.Current is always null.
Test: