Class HttpRequestDataBuilder
Builds concrete HttpRequestData instances for Azure Functions HTTP-trigger tests.
Inherited Members
Namespace: FastMoq.AzureFunctions.Http
Assembly: FastMoq.AzureFunctions.dll
Syntax
public sealed class HttpRequestDataBuilder
Constructors
HttpRequestDataBuilder(FunctionContext)
Initializes a new HttpRequestDataBuilder instance.
Declaration
public HttpRequestDataBuilder(FunctionContext functionContext)
Parameters
| Type | Name | Description |
|---|---|---|
| FunctionContext | functionContext | The function context to associate with the request. |
Methods
Build()
Builds the configured HttpRequestData instance.
Declaration
public HttpRequestData Build()
Returns
| Type | Description |
|---|---|
| HttpRequestData | A concrete HttpRequestData suitable for tests. |
WithBody(Stream, string?)
Sets the request body from an existing stream.
Declaration
public HttpRequestDataBuilder 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 |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithBody(string, Encoding?, string?)
Sets the request body from a string payload.
Declaration
public HttpRequestDataBuilder 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 |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithClaimsPrincipal(ClaimsPrincipal)
Adds all identities from the supplied principal to the request.
Declaration
public HttpRequestDataBuilder WithClaimsPrincipal(ClaimsPrincipal principal)
Parameters
| Type | Name | Description |
|---|---|---|
| ClaimsPrincipal | principal | The principal whose identities should be added. |
Returns
| Type | Description |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithCookie(string, string, string?, string?)
Adds a request cookie.
Declaration
public HttpRequestDataBuilder WithCookie(string name, string value, string? path = null, string? domain = 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. |
Returns
| Type | Description |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithHeader(string, string)
Adds a request header.
Declaration
public HttpRequestDataBuilder WithHeader(string name, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The header name. |
| string | value | The header value. |
Returns
| Type | Description |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithIdentity(ClaimsIdentity)
Adds a claims identity to the request.
Declaration
public HttpRequestDataBuilder WithIdentity(ClaimsIdentity identity)
Parameters
| Type | Name | Description |
|---|---|---|
| ClaimsIdentity | identity | The identity to add. |
Returns
| Type | Description |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithJsonBody<TValue>(TValue, JsonSerializerOptions?)
Sets the request body from a JSON payload.
Declaration
public HttpRequestDataBuilder 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 |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The payload type. |
WithMethod(string)
Sets the HTTP method.
Declaration
public HttpRequestDataBuilder WithMethod(string method)
Parameters
| Type | Name | Description |
|---|---|---|
| string | method | The HTTP method. |
Returns
| Type | Description |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithQueryParameter(string, string?)
Adds a query-string parameter.
Declaration
public HttpRequestDataBuilder WithQueryParameter(string name, string? value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The parameter name. |
| string | value | The parameter value. |
Returns
| Type | Description |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithUrl(string)
Sets the request URL.
Declaration
public HttpRequestDataBuilder WithUrl(string url)
Parameters
| Type | Name | Description |
|---|---|---|
| string | url | The absolute request URL. |
Returns
| Type | Description |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |
WithUrl(Uri)
Sets the request URL.
Declaration
public HttpRequestDataBuilder WithUrl(Uri url)
Parameters
| Type | Name | Description |
|---|---|---|
| Uri | url | The absolute request URL. |
Returns
| Type | Description |
|---|---|
| HttpRequestDataBuilder | The current HttpRequestDataBuilder instance. |