Class HttpResponseDataBuilder
Builds concrete HttpResponseData instances for Azure Functions HTTP-trigger tests.
Inherited Members
Namespace: FastMoq.AzureFunctions.Http
Assembly: FastMoq.AzureFunctions.dll
Syntax
public sealed class HttpResponseDataBuilder
Constructors
HttpResponseDataBuilder(FunctionContext)
Initializes a new HttpResponseDataBuilder instance.
Declaration
public HttpResponseDataBuilder(FunctionContext functionContext)
Parameters
| Type | Name | Description |
|---|---|---|
| FunctionContext | functionContext | The function context to associate with the response. |
Methods
Build()
Builds the configured HttpResponseData instance.
Declaration
public HttpResponseData Build()
Returns
| Type | Description |
|---|---|
| HttpResponseData | A concrete HttpResponseData suitable for tests. |
WithBody(Stream, string?)
Sets the response body from an existing stream.
Declaration
public HttpResponseDataBuilder WithBody(Stream body, string? contentType = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | body | The body stream. |
| string | contentType | An optional content-type header value. |
Returns
| Type | Description |
|---|---|
| HttpResponseDataBuilder | The current HttpResponseDataBuilder instance. |
WithBody(string, Encoding?, string?)
Sets the response body from a string payload.
Declaration
public HttpResponseDataBuilder WithBody(string body, Encoding? encoding = null, string? contentType = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | body | The body payload. |
| Encoding | encoding | The text encoding. Defaults to UTF-8. |
| string | contentType | An optional content-type header value. |
Returns
| Type | Description |
|---|---|
| HttpResponseDataBuilder | The current HttpResponseDataBuilder instance. |
WithCookie(string, string, string?, string?, bool?, bool?)
Adds a response cookie.
Declaration
public HttpResponseDataBuilder WithCookie(string name, string value, string? path = null, string? domain = null, bool? httpOnly = null, bool? secure = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The cookie name. |
| string | value | The cookie value. |
| string | path | An optional cookie path. |
| string | domain | An optional cookie domain. |
| bool? | httpOnly | An optional HttpOnly flag. |
| bool? | secure | An optional Secure flag. |
Returns
| Type | Description |
|---|---|
| HttpResponseDataBuilder | The current HttpResponseDataBuilder instance. |
WithHeader(string, string)
Adds a response header.
Declaration
public HttpResponseDataBuilder WithHeader(string name, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The header name. |
| string | value | The header value. |
Returns
| Type | Description |
|---|---|
| HttpResponseDataBuilder | The current HttpResponseDataBuilder instance. |
WithJsonBody<TValue>(TValue, JsonSerializerOptions?)
Sets the response body from a JSON payload.
Declaration
public HttpResponseDataBuilder WithJsonBody<TValue>(TValue value, JsonSerializerOptions? jsonSerializerOptions = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TValue | value | The payload to serialize. |
| JsonSerializerOptions | jsonSerializerOptions | Optional serializer options. |
Returns
| Type | Description |
|---|---|
| HttpResponseDataBuilder | The current HttpResponseDataBuilder instance. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The payload type. |
WithStatusCode(HttpStatusCode)
Sets the response status code.
Declaration
public HttpResponseDataBuilder WithStatusCode(HttpStatusCode statusCode)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpStatusCode | statusCode | The HTTP status code. |
Returns
| Type | Description |
|---|---|
| HttpResponseDataBuilder | The current HttpResponseDataBuilder instance. |