StubApiResponse class¶
Defined in
Namespace: Refit.Testing
Assembly: Refit.Testing.dll
Full name: Refit.Testing.StubApiResponse<T>
Modifiers: public sealed
Summary¶
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
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¶
| Name | Summary |
|---|---|
| .ctor |
Properties¶
| Name | Summary |
|---|---|
| Content | Gets the deserialized response content. |
| HasContent | Gets a value indicating whether deserialized content is available. |
| IsSuccessfulWithContent | Gets a value indicating whether the request was successful and content is available. |
| Headers | Gets the HTTP response headers. |
| ContentHeaders | Gets the HTTP response content headers. |
| IsSuccessStatusCode | Gets a value indicating whether the response has a success status code. |
| IsSuccessful | Gets a value indicating whether the request was successful. |
| IsReceived | Gets a value indicating whether a response was received from the server. |
| StatusCode | Gets the HTTP response status code. |
| ReasonPhrase | Gets the reason phrase sent with the status code. |
| RequestMessage | Gets the HTTP request message which led to this response. |
| Version | Gets the HTTP message version. |
| Error | Gets the exception object in case of an unsuccessful request or response. |
Methods¶
| Name | Summary |
|---|---|
| HasRequestError | Reports the request-phase error, if any, exposed by [Error](# |
| HasResponseError | Reports the response-phase error, if any, exposed by [Error](# |
| Dispose | No-op; the stub owns no disposable resources. |