Skip to content

StubApiResponse class

Defined in

Namespace: Refit.Testing Assembly: Refit.Testing.dll Full name: Refit.Testing.StubApiResponse<T> Modifiers: public sealed

Summary

View source

A 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.

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481, net471

Class hierarchy
classDiagram
class StubApiResponse~T~
class IApiResponse~T~ {
    <>
}
IApiResponse~T~ <|.. StubApiResponse~T~
class IApiResponse {
    <>
}
IApiResponse <|.. StubApiResponse~T~
class IDisposable {
    <>
}
IDisposable <|.. StubApiResponse~T~

Implements: IApiResponse, IApiResponse, IDisposable

Remarks

The nullability-narrowing contracts (for example IsSuccessfulWithContent implying non-null Content) come from the interface declaration, so a consumer's if (response.IsSuccessfulWithContent) flow-narrows exactly as it does against a real response. Prefer StubHttp for end-to-end tests; reach for this only when the code under test is handed an IApiResponse directly.

Constructors

NameSummary
.ctor

Properties

NameSummary
ContentGets the deserialized response content.
HasContentGets a value indicating whether deserialized content is available.
IsSuccessfulWithContentGets a value indicating whether the request was successful and content is available.
HeadersGets the HTTP response headers.
ContentHeadersGets the HTTP response content headers.
IsSuccessStatusCodeGets a value indicating whether the response has a success status code.
IsSuccessfulGets a value indicating whether the request was successful.
IsReceivedGets a value indicating whether a response was received from the server.
StatusCodeGets the HTTP response status code.
ReasonPhraseGets the reason phrase sent with the status code.
RequestMessageGets the HTTP request message which led to this response.
VersionGets the HTTP message version.
ErrorGets the exception object in case of an unsuccessful request or response.

Methods

NameSummary
HasRequestErrorReports the request-phase error, if any, exposed by [Error](#
HasResponseErrorReports the response-phase error, if any, exposed by [Error](#
DisposeNo-op; the stub owns no disposable resources.
Inherited members