richardszalay/mockhttp

Overwrite same endpoint with different result

Merhex opened this issue · 3 comments

Hello,

Is it possible to return another result from the exact same endpoint without clearing the handler?

Regards,
Axel

Apologies for the delayed reply.

Have you tried using Expect (combined with BackendDefinitionBehavior.Always if you have other requests)?

If you have the handler, you can simply call Respond again.
I use a helper method like this:
private MockedRequest _getSignature;
public void SetupGetSignature(OmsSignatureResult result)
{
_getSignature ??= _mockHttp.When(HttpMethod.Post, "/api/v1/signature");
_getSignature.Respond(request => SetupSignatureResponse(request, result));
}

I think between my answer and @Timores's, that should cover your question. Please open another issue if it doesn't.