Skip to content

Add GetMessageHandler() to HttpMock#94

Merged
dennisdoomen merged 3 commits intomainfrom
copilot/add-get-message-handler
Apr 10, 2026
Merged

Add GetMessageHandler() to HttpMock#94
dennisdoomen merged 3 commits intomainfrom
copilot/add-get-message-handler

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

Summary

Adds a GetMessageHandler() method to HttpMock alongside the existing GetClient() and GetClientFactory() methods. It returns the underlying MockHttpMessageHandler typed as HttpMessageHandler, allowing users to wire the mock handler directly into an HttpClient or other infrastructure that accepts an HttpMessageHandler.

Changes

  • Mockly/HttpMock.cs: Added GetMessageHandler() public method with XML doc comment and CA1024 suppression (consistent with GetClient() and GetClientFactory())
  • Mockly.Specs/HttpMockSpecs.cs: Added WhenGettingMessageHandler test class with a passing test
  • Mockly.ApiVerificationTests/ApprovedApi/net8.0.verified.txt: Added new method to approved API surface
  • Mockly.ApiVerificationTests/ApprovedApi/net472.verified.txt: Added new method to approved API surface
  • website/docs/quick-start.md: Added a new "Using a Raw HttpMessageHandler" section
  • website/docs/usage.md: Added a section comparing all three wiring options (GetClient, GetClientFactory, GetMessageHandler)

Usage

var mock = new HttpMock();
mock.ForGet().WithPath("/ping").RespondsWithStatus(HttpStatusCode.OK);

HttpMessageHandler handler = mock.GetMessageHandler();
using var client = new HttpClient(handler) { BaseAddress = new Uri("https://localhost/") };

var response = await client.GetAsync("/ping");

Copilot AI and others added 2 commits April 10, 2026 07:25
Agent-Logs-Url: https://github.com/dennisdoomen/mockly/sessions/fcb676b8-3631-4914-b34c-a17512d79051

Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dennisdoomen/mockly/sessions/fcb676b8-3631-4914-b34c-a17512d79051

Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
Comment thread Mockly.Specs/HttpMockSpecs.cs Outdated
public class WhenGettingMessageHandler
{
[Fact]
public async Task GetMessageHandler_returns_handler_that_intercepts_requests()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public async Task GetMessageHandler_returns_handler_that_intercepts_requests()
public async Task Can_return_a_message_handler_that_intercepts_requests()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6979ce2.

Agent-Logs-Url: https://github.com/dennisdoomen/mockly/sessions/7d566c31-4f98-4a1e-81c6-09037d9cbdeb

Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 10, 2026

Coverage Report for CI Build 24231931000

Coverage increased (+0.04%) to 83.649%

Details

  • Coverage increased (+0.04%) from the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1010
Covered Lines: 899
Line Coverage: 89.01%
Relevant Branches: 311
Covered Branches: 206
Branch Coverage: 66.24%
Branches in Coverage %: Yes
Coverage Strength: 334.8 hits per line

💛 - Coveralls


var handler = mock.GetMessageHandler();

using var client = new HttpClient(handler)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 10, 2026

Test Results

  3 files  ±0    3 suites  ±0   4s ⏱️ -1s
 89 tests +1   89 ✅ +1  0 💤 ±0  0 ❌ ±0 
175 runs  +2  175 ✅ +2  0 💤 ±0  0 ❌ ±0 

Results for commit 6979ce2. ± Comparison against base commit 5a70745.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants