You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The HttpClient supports performance optimizations due to its overload of SendAsync with the HttpCompletionOption argument.
If I want to write testable code I inject a mock or dummy deriving from HttpClient. The base class (HttpMessageInvoker) defines SendAsync(HttpRequestMessage, CancellationToken) as virtual, so it can be overridden in the mock or dummy.
The overloads of the SendAsync method in HttpClient are not specified as virtual, so currently one has to decide: Write testable or performant code.
It would be great if the overloads of the SendAsync woyuld be declared virtual.
The text was updated successfully, but these errors were encountered:
Mocking the invoker should generally be sufficient.
The HttpCompletionOption overloads are a very thin wrapper around the message invoker. They only specify if, after calling HttpMessageInvoker.SendAsync(), it should also call HttpContent.LoadIntoBufferAsync().
This has already been discussed at length in dotnet/runtime#14535, with the decision being to not make these virtual. If you believe there's more to add to that conversation, please open a new issue there on the dotnet/runtime repo.
The
HttpClient
supports performance optimizations due to its overload ofSendAsync
with theHttpCompletionOption
argument.If I want to write testable code I inject a mock or dummy deriving from
HttpClient
. The base class (HttpMessageInvoker
) definesSendAsync(HttpRequestMessage, CancellationToken)
as virtual, so it can be overridden in the mock or dummy.The overloads of the
SendAsync
method inHttpClient
are not specified as virtual, so currently one has to decide: Write testable or performant code.It would be great if the overloads of the
SendAsync
woyuld be declaredvirtual
.The text was updated successfully, but these errors were encountered: