dotnet-testing

Write tests for code calling APIMatic-generated .NET SDKs using a fake HttpMessageHandler seam.

Updated Jun 9, 2026
One-click install
npx skills add https://github.com/apimatic/plugin-marketplace --skill dotnet-testing-apimatic
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-testing
Source: https://github.com/apimatic/plugin-marketplace/tree/main/plugins/maxio-sdk/skills/dotnet-testing
Command: npx skills add https://github.com/apimatic/plugin-marketplace --skill dotnet-testing-apimatic

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Testing code that calls an APIMatic-generated .NET SDK is tricky because the SDK ships no mocking helpers, and naive tests either hit the real network or assert SDK internals instead of real behaviour. This Skill shows how to use the HttpClient constructor seam to fake HTTP responses and write meaningful tests. ## Core Features & Use Cases - HttpMessageHandler test seam: Build a reusable StubHandler that captures every request and returns canned responses, so no real network calls happen. - Error and result-path coverage: Assert typed SdkException<{Operation}Error> or SdkException<RawError> on failure paths, and test the non-throwing ApiResult variant directly. - Request and retry assertions: Verify outgoing method, path, query, and body, plus retry behaviour for status faults versus transport faults and write-once guarantees. - Use Case: You are writing integration-layer tests for a C# service that calls a generated SDK client. Use this Skill to stub a 422 response, assert the typed error is thrown, and confirm the outgoing POST body contains the expected fields. ## Quick Start Ask your AI agent to write xUnit tests for the code calling your APIMatic .NET SDK using a stubbed HttpMessageHandler, covering success, error, and retry paths.

Frequently Asked Questions about dotnet-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test code that calls an APIMatic .NET SDK without network calls?▼

Pass an HttpClient backed by a fake HttpMessageHandler into the SDK client's constructor. The handler returns canned HttpResponseMessage objects and records each request, so tests run entirely in memory.

How do I test SDK error responses in C#?▼

Stub a non-2xx response and assert the thrown SdkException<TError>. TError is the operation's typed {Operation}Error when one exists, or RawError directly otherwise, so assert the type matching your operation.

Can I use Moq or NSubstitute to mock the SDK client?▼

Yes, mocking libraries work by mocking HttpMessageHandler.SendAsync, which is protected, so Moq requires Protected(). A hand-written stub handler avoids that friction and also captures requests for assertions.

Does the SDK retry failed requests in tests?▼

Status retries (408/429/5xx) apply only to GET/HEAD/PUT/OPTIONS by default, while a stub that throws HttpRequestException is retried on every verb including POST. Test status faults and transport faults separately since they are distinct retry triggers.

How do I test the SDK when it is registered via dependency injection?▼

The SDK's Add{Api}Client resolves the default unnamed IHttpClientFactory client. Register your stub handler on Options.DefaultName via ConfigurePrimaryHttpMessageHandler, then resolve the client from the service provider.