Skip to content

Refit.Testing namespace

Part of the Refit.Testing package.

TypeKindSummary
NetworkBehaviorclassDeterministic network-condition simulation for [StubHttp](# modelled on Retrofit's NetworkBehavior. Attach one to a handler to inject latency, latency variance, simulated network failures (a thrown HttpRequestException) and simulated HTTP errors (a non-2xx response), so retry, timeout and [ApiException](# handling can be exercised under test.
ReplyclassFactory for the [StubResponse](# a [StubHttp](# route returns. [With](# serializes a typed object with the client's own serializer, so tests never hand-write JSON.
RouteclassFactory for the common [RouteMatcher](# shapes, one per HTTP method. Each takes a path template that mirrors the route on the Refit interface, e.g. Route.Get("/users/{id}").
RouteMatcherclassMatches an incoming request by HTTP method and a path [Template](# that mirrors the [Get("/users/{id}")] attributes on a Refit interface. Build the common cases with the [Route](# factory; set the optional properties directly for finer matching.
StubApiResponseclassA hand-written [IApiResponse](# for unit-testing code that consumes a Refit interface returning [IApiResponse](# or [ApiResponse](# without going through HTTP. Every member is an init-only property, so a test configures exactly the fields it needs and leaves the rest defaulted.
StubHttpclassA declarative test HttpMessageHandler for Refit clients, written as a route table: each entry pairs a [RouteMatcher](# (built with [Route](# with a [StubResponse](# (built with [Reply](# Populate it with a collection initializer whose templates mirror the routes declared on the Refit interface.
StubResponseclassThe response a [StubHttp](# returns for a matched [RouteMatcher](# Build it with the [Reply](# factory rather than constructing it directly; the properties are exposed so a test can read what a reply carries.