Definition
Assembly: CloudNimble.Breakdance.DotHttp.dll Namespace: CloudNimble.Breakdance.DotHttp Inheritance: System.ObjectSyntax
Summary
Provides smart assertion helpers for HTTP responses that go beyond simple status code checking.Remarks
Detects common API error patterns like 200 OK responses that contain error payloads.Examples
Methods
AssertBodyContainsAsync
Validates that the response body contains the specified text.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
response | System.Net.Http.HttpResponseMessage | The HTTP response. |
expectedText | string | The text that should be present in the body. |
maxBodyPreviewLength | int | Maximum length of body content to include in error messages. |
Returns
Type:System.Threading.Tasks.Task
Examples
AssertContentType
Validates that the response Content-Type matches the expected value.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
response | System.Net.Http.HttpResponseMessage | The HTTP response. |
expectedContentType | string | The expected Content-Type (e.g., “application/json”). |
Examples
AssertHeader
Validates that the response contains a specific header.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
response | System.Net.Http.HttpResponseMessage | The HTTP response. |
headerName | string | The expected header name. |
expectedValue | string | Optional expected header value. |
Examples
AssertNoErrorsInBodyAsync
Validates that the response body does not contain error patterns.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
response | System.Net.Http.HttpResponseMessage | The HTTP response. |
maxBodyPreviewLength | int | Maximum length of body content to include in error messages. |
Returns
Type:System.Threading.Tasks.Task
Examples
AssertStatusCodeAsync
Validates that the response status code matches the expected value.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
response | System.Net.Http.HttpResponseMessage | The HTTP response. |
expectedStatusCode | int | The expected status code. |
maxBodyPreviewLength | int | Maximum length of body content to include in error messages. |
Returns
Type:System.Threading.Tasks.Task
Examples
AssertValidResponseAsync
Validates that the response meets common API contract expectations.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
response | System.Net.Http.HttpResponseMessage | The HTTP response to validate. |
checkStatusCode | bool | Whether to check the status code for success. Default is true. |
checkContentType | bool | Whether to verify Content-Type is present when body exists. Default is true. |
checkBodyForErrors | bool | Whether to check for error patterns in the response body. Default is true. |
logResponseOnFailure | bool | Whether to include the response body in failure messages. Default is true. |
maxBodyPreviewLength | int | Maximum length of body content to include in error messages. Default is 500. |
Returns
Type:System.Threading.Tasks.Task
A task that completes when validation is done.
Exceptions
| Exception | Description |
|---|---|
DotHttpAssertionException | Thrown when an assertion fails. |