Conversation
test: Add comprehensive HttpClient mocking tests chore: Cleanup unused usings and minor formatting
Removes the commented-out `CreateClientFactory` method from `MockHttpMessageHandlerExtensions`.
This was referenced Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces comprehensive and fluent support for mocking
HttpClientandHttpMessageHandlerwithin Moq.AutoMock, significantly simplifying the testing of HTTP-dependent code.Changes Made
HttpClientResolverhas been added toAutoMockerto automatically provideHttpClientinstances backed by a configurableHttpMessageHandler.SetupHttpGet,SetupHttpPost,SetupHttpPut,SetupHttpDelete,SetupHttpHead) allow for easy setup of specific HTTP requests based on URL, request content, or custom predicates.ReturnsResponsemethods support various response types (plain text, JSON, byte arrays, streams) with custom status codes and headers. Stream-based responses are handled to ensure reusability across multiple requests.VerifyHttpGet,VerifyHttpPost,VerifyHttpPut,VerifyHttpDelete,VerifyHttpHeadextensions are included for verifying specific HTTP request invocations.RequestMatcherandRequestPredicatefor more robust and efficient matching ofHttpRequestMessageobjects.Why These Changes
These changes aim to streamline the unit testing experience for applications consuming external HTTP services. By providing a rich, fluent, and integrated mocking API for
HttpClientandHttpMessageHandler, developers can more easily isolate and test their code without making actual network calls, leading to faster and more reliable tests. The automatic resolution ofHttpClientfurther enhances the seamless integration with AutoMocker's dependency injection capabilities.How to Test
The added unit tests in
Moq.AutoMock.Tests/DescribeHttpClient.csandMoq.AutoMock.Tests/DescribeHttpMessageHandler.csdemonstrate the usage and verify the functionality of the new HTTP mocking capabilities. These tests can be run to confirm the feature works as expected.Checklist