79526738

Date: 2025-03-21 23:32:37
Score: 2
Natty:
Report link

If anyone was wondering for an answer, basically I wanted to test the code within the service bus message handler (processmessageasync) and was initially looking for a way to simulate message dispatching and then processing. I was a new engineer and saw our legacy code had untested code within the handler that was not separated to its own function. As a new eng, I asked the question assuming that was the norm.

Long story short (and what Jesse commented in my post) is that my question is effectively nonsensical. We are not concerned with testing the handler but our own logic.

As such, just abstract the code within the handler to a function and write a unit test of that instead :) Then you can moq the message and its completion handler also.

ex:

// Not written with exact syntax

// If want to unit test everything, don't do this
ProcessMessageAsync (args) => 
{
    data1 = args.smt
    etc
    etc
}

// Just do this
ProcessMessageAsync (args) =>
{
    MyMessageHandlerFunction(args) // test this
}


....

// just unpack everything here and mock the args and message completion handler also

MyMessageHandlerFunction(args){
    data1 = args.smt
    etc
    etc
}

All in all, this was basically a dumb question lol. Thanks to Jesse who still put in time to answer it.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (2): was wondering
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: linglingslinguini