Skip to content

Commit 63862cd

Browse files
authored
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
1 parent 8cd5b56 commit 63862cd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Tool/SystemTestingTools/Internal/HttpCallInterceptor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ private static async Task<HttpResponseMessage> FindStub(HttpRequestMessage reque
132132
if (match.Exception != null)
133133
throw match.Exception;
134134

135-
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
135+
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
136+
var clonedRequest = await request.Clone();
137+
138+
clonedResponse.RequestMessage = clonedRequest;
139+
return clonedResponse;
136140
}
137141
}
138142
}

0 commit comments

Comments
 (0)