From 63862cd432c8fc23b1f1ca2a761f26261435ab43 Mon Sep 17 00:00:00 2001 From: amikhaildev Date: Mon, 21 Nov 2022 16:18:41 +1100 Subject: [PATCH] Set RequestMessage in matched StubbedResponse When running AcceptanceTests for error scenarios using Refit, it throws null reference exception. This is caused by refit trying to access response.RequestMessage.Method while response.RequestMessage is null. This change resolves that issue by setting the original request as response.RequestMessage. It will also help if any tested code is accessing response.RequestMessage. The refit method that throws null reference exception https://github.com/reactiveui/refit/blob/569108a65079d364647f06437f977df8145fc578/Refit/RefitSettings.cs#L233 --- Tool/SystemTestingTools/Internal/HttpCallInterceptor.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tool/SystemTestingTools/Internal/HttpCallInterceptor.cs b/Tool/SystemTestingTools/Internal/HttpCallInterceptor.cs index a1fc6f4..2705e97 100644 --- a/Tool/SystemTestingTools/Internal/HttpCallInterceptor.cs +++ b/Tool/SystemTestingTools/Internal/HttpCallInterceptor.cs @@ -132,7 +132,11 @@ private static async Task FindStub(HttpRequestMessage reque if (match.Exception != null) throw match.Exception; - return await match.Response.Clone(); // we clone because if the response is used more than one time, the content stream has been read and can't be read again + var clonedResponse = await match.Response.Clone(); // we clone because if the response is used more than one time, the content stream has been read and can't be read again + var clonedRequest = await request.Clone(); + + clonedResponse.RequestMessage = clonedRequest; + return clonedResponse; } } }