Class MockerHttpExtensions
Mocker Http Extensions Class.
Inherited Members
Namespace: FastMoq.Extensions
Assembly: FastMoq.Core.dll
Syntax
public static class MockerHttpExtensions
Methods
CreateHttpClient(Mocker, string, string, HttpStatusCode, string)
Creates an HTTP client backed by FastMoq-managed HTTP dependencies.
Declaration
public static HttpClient CreateHttpClient(this Mocker mocker, string clientName = "FastMoqHttpClient", string baseAddress = "http://localhost", HttpStatusCode statusCode = HttpStatusCode.OK, string stringContent = "[{'id':1}]")
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | |
| string | clientName | |
| string | baseAddress | |
| HttpStatusCode | statusCode | |
| string | stringContent |
Returns
| Type | Description |
|---|---|
| HttpClient |
Remarks
This entry point remains supported after v5. New tests should prefer the provider-neutral request helpers in this class for HTTP behavior. Advanced protected-member setups remain available from the Moq provider package for migration scenarios.
GetContentBytesAsync(HttpContent)
Gets the content bytes.
Declaration
public static Task<byte[]> GetContentBytesAsync(this HttpContent content)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContent | content | The content. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | byte[]. |
GetContentStreamAsync(HttpContent)
Gets the content stream.
Declaration
public static Task<Stream> GetContentStreamAsync(this HttpContent content)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContent | content | The content. |
Returns
| Type | Description |
|---|---|
| Task<Stream> | System.IO.Stream. |
WhenHttpRequest(Mocker, Func<HttpRequestMessage, bool>, Func<HttpResponseMessage>)
Configures a provider-neutral HTTP response for requests that match the supplied predicate.
Declaration
public static void WhenHttpRequest(this Mocker mocker, Func<HttpRequestMessage, bool> requestPredicate, Func<HttpResponseMessage> responseFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The mocker. |
| Func<HttpRequestMessage, bool> | requestPredicate | Predicate used to match an outgoing request. |
| Func<HttpResponseMessage> | responseFactory | Factory used to create the HTTP response for a matching request. |
WhenHttpRequest(Mocker, HttpMethod, string, Func<HttpResponseMessage>)
Configures a provider-neutral HTTP response for a specific method and request URI or path.
Declaration
public static void WhenHttpRequest(this Mocker mocker, HttpMethod method, string requestUriOrPath, Func<HttpResponseMessage> responseFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The mocker. |
| HttpMethod | method | The expected HTTP method. |
| string | requestUriOrPath | The absolute URI or relative path to match. |
| Func<HttpResponseMessage> | responseFactory | Factory used to create the HTTP response for a matching request. |
WhenHttpRequestJson(Mocker, HttpMethod, string, string, HttpStatusCode)
Configures a provider-neutral JSON response for a specific method and request URI or path.
Declaration
public static void WhenHttpRequestJson(this Mocker mocker, HttpMethod method, string requestUriOrPath, string json, HttpStatusCode statusCode = HttpStatusCode.OK)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The mocker. |
| HttpMethod | method | The expected HTTP method. |
| string | requestUriOrPath | The absolute URI or relative path to match. |
| string | json | The JSON payload returned to matching requests. |
| HttpStatusCode | statusCode | The response status code. |