Skip to content

refactor: extract shared FakeHttpClientFactory and remove duplicated JsonResponse helpers#917

Merged
Aaronontheweb merged 3 commits into
netclaw-dev:devfrom
Aaronontheweb:refactor/extract-fake-http-client-factory
May 7, 2026
Merged

refactor: extract shared FakeHttpClientFactory and remove duplicated JsonResponse helpers#917
Aaronontheweb merged 3 commits into
netclaw-dev:devfrom
Aaronontheweb:refactor/extract-fake-http-client-factory

Conversation

@Aaronontheweb
Copy link
Copy Markdown
Collaborator

Summary

  • Adds FakeHttpClientFactory to Netclaw.Tests.Utilities — a shared IHttpClientFactory implementation that wraps FakeHttpMessageHandler, replacing five identical StubHttpClientFactory/StubHttpMessageHandler nested class pairs spread across test files
  • Replaces four identical private JsonResponse(object body, ...) helpers in the same test files with direct calls to FakeHttpMessageHandler.JsonResponse<T>, which already existed for this purpose
  • Removes now-orphaned using System.Net and using System.Text directives from the affected files
  • Adds Microsoft.Extensions.Http package reference to Netclaw.Tests.Utilities.csproj (via central package management) so IHttpClientFactory resolves in the utilities assembly

Closes #911

Files changed

  • src/Netclaw.Tests.Utilities/FakeHttpClientFactory.cs — new shared factory
  • src/Netclaw.Tests.Utilities/Netclaw.Tests.Utilities.csprojMicrosoft.Extensions.Http reference
  • src/Netclaw.Cli.Tests/Cli/DaemonApiAuthenticationTests.cs — removed stubs and local helper
  • src/Netclaw.Cli.Tests/Doctor/ContextWindowDoctorCheckTests.cs — removed stubs and local helper
  • src/Netclaw.Cli.Tests/Doctor/McpServersDoctorCheckTests.cs — removed stubs and local helper
  • src/Netclaw.Cli.Tests/Mcp/McpCommandTests.cs — removed stubs and local helper

Test plan

  • dotnet test passes for Netclaw.Cli.Tests — 47/47 tests green
  • dotnet slopwatch analyze — 0 issues
  • Add-FileHeaders.ps1 -Verify — all headers present

Five test files each defined identical StubHttpClientFactory and
StubHttpMessageHandler nested classes. Replace all five with a shared
FakeHttpClientFactory in Netclaw.Tests.Utilities that wraps the existing
FakeHttpMessageHandler.

Adds Microsoft.Extensions.Http package reference to Netclaw.Tests.Utilities
so IHttpClientFactory is resolvable in the utilities project.

Closes netclaw-dev#911
…eHandler.JsonResponse

Four test files each defined a private JsonResponse(object body, ...) helper
that was a verbatim copy of FakeHttpMessageHandler.JsonResponse<T>. Remove all
four and update call sites to use the shared static method directly. Also drop
the now-orphaned System.Net and System.Text using directives.
@Aaronontheweb Aaronontheweb enabled auto-merge (squash) May 7, 2026 19:40
@Aaronontheweb Aaronontheweb merged commit 14d050e into netclaw-dev:dev May 7, 2026
6 of 7 checks passed
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

Successfully merging this pull request may close these issues.

refactor: extract shared StubHttpClientFactory from test files into Netclaw.Tests.Utilities

1 participant