Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Net.Http.HttpClient add virtual to SendAsync overloads to allow performant and testable code #1187

Closed
lennybacon opened this issue Apr 1, 2020 · 1 comment

Comments

@lennybacon
Copy link

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.

@scalablecory
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants