Class TestHttpClient
Implements a HttpClient compatible client with additional capabilities, like disabling connection reuse. This is intended for unit testing purposes like verifying that load balancing actually works.
Namespace: Neon.Xunit
Assembly: Neon.Xunit.dll
Syntax
public class TestHttpClient
Constructors
TestHttpClient(bool, HttpMessageHandler, bool)
Constructor.
Declaration
public TestHttpClient(bool disableConnectionReuse, HttpMessageHandler handler = null, bool disposeHandler = false)
Parameters
Type | Name | Description |
---|---|---|
bool | disableConnectionReuse | Indicates whether connection reuse should be disabled. |
HttpMessageHandler | handler | Optionally specifies a message handler. |
bool | disposeHandler | Optionally specifies that the handler should be disposed when this instance is disposed. |
Properties
BaseAddress
The base address that to be used when sending requests.
Declaration
public Uri BaseAddress { get; set; }
Property Value
Type | Description |
---|---|
Uri |
DefaultRequestHeaders
The headers that should be sent with each request.
Declaration
public HttpRequestHeaders DefaultRequestHeaders { get; }
Property Value
Type | Description |
---|---|
HttpRequestHeaders |
MaxResponseContentBufferSize
the maximum number of bytes to buffer when reading the response content. This defaults to 2GiB.
Declaration
public long MaxResponseContentBufferSize { get; set; }
Property Value
Type | Description |
---|---|
long |
Timeout
The maximum time allowed before a request times out.
Declaration
public TimeSpan Timeout { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
Methods
DeleteAsync(string)
Sends a DELETE request.
Declaration
public Task<HttpResponseMessage> DeleteAsync(string requestUri)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
DeleteAsync(string, CancellationToken)
Sends a DELETE request.
Declaration
public Task<HttpResponseMessage> DeleteAsync(string requestUri, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
DeleteAsync(Uri)
Sends a DELETE request.
Declaration
public Task<HttpResponseMessage> DeleteAsync(Uri requestUri)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
DeleteAsync(Uri, CancellationToken)
Sends a DELETE request.
Declaration
public Task<HttpResponseMessage> DeleteAsync(Uri requestUri, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(bool)
Releases all associated resources.
Declaration
protected void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Pass |
GetAsync(string)
Sends a GET request.
Declaration
public Task<HttpResponseMessage> GetAsync(string requestUri)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
GetAsync(string, HttpCompletionOption)
Sends a GET request.
Declaration
public Task<HttpResponseMessage> GetAsync(string requestUri, HttpCompletionOption completionOption)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
HttpCompletionOption | completionOption | The copmpletion options. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
GetAsync(string, HttpCompletionOption, CancellationToken)
Sends a GET request.
Declaration
public Task<HttpResponseMessage> GetAsync(string requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
HttpCompletionOption | completionOption | The copmpletion options. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
GetAsync(string, CancellationToken)
Sends a GET request.
Declaration
public Task<HttpResponseMessage> GetAsync(string requestUri, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
GetAsync(Uri)
Sends a GET request.
Declaration
public Task<HttpResponseMessage> GetAsync(Uri requestUri)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
GetAsync(Uri, HttpCompletionOption)
Sends a GET request.
Declaration
public Task<HttpResponseMessage> GetAsync(Uri requestUri, HttpCompletionOption completionOption)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
HttpCompletionOption | completionOption | The completion option. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
GetAsync(Uri, HttpCompletionOption, CancellationToken)
Sends a GET request.
Declaration
public Task<HttpResponseMessage> GetAsync(Uri requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
HttpCompletionOption | completionOption | The completion option. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
GetAsync(Uri, CancellationToken)
Sends a GET request.
Declaration
public Task<HttpResponseMessage> GetAsync(Uri requestUri, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
GetByteArrayAsync(string)
Performs a GET request and returns the response contents as a byte array.
Declaration
public Task<byte[]> GetByteArrayAsync(string requestUri)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<byte[]> | The content bytes. |
GetByteArrayAsync(Uri)
Performs a GET request and returns the response contents as a byte array.
Declaration
public Task<byte[]> GetByteArrayAsync(Uri requestUri)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<byte[]> | The content bytes. |
GetStreamAsync(string)
Performs a GET request and returns the response as a stream.
Declaration
public Task<Stream> GetStreamAsync(string requestUri)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<Stream> | The response stream. |
GetStreamAsync(Uri)
Performs a GET request and returns the response as a stream.
Declaration
public Task<Stream> GetStreamAsync(Uri requestUri)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<Stream> | The response stream. |
GetStringAsync(string)
Performs a GET request and returns the response as a string.
Declaration
public Task<string> GetStringAsync(string requestUri)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<string> | The response string. |
GetStringAsync(Uri)
Performs a GET request and returns the response as a string.
Declaration
public Task<string> GetStringAsync(Uri requestUri)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
Returns
Type | Description |
---|---|
Task<string> | The response string. |
PostAsync(string, HttpContent)
Performs a POST request.
Declaration
public Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
HttpContent | content | The request contents. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
PostAsync(string, HttpContent, CancellationToken)
Performs a POST request.
Declaration
public Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
HttpContent | content | The request contents. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
PostAsync(Uri, HttpContent)
Performs a POST request.
Declaration
public Task<HttpResponseMessage> PostAsync(Uri requestUri, HttpContent content)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
HttpContent | content | The request contents. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
PostAsync(Uri, HttpContent, CancellationToken)
Performs a POST request.
Declaration
public Task<HttpResponseMessage> PostAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
HttpContent | content | The request contents. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
PutAsync(string, HttpContent)
Performs a PUT request.
Declaration
public Task<HttpResponseMessage> PutAsync(string requestUri, HttpContent content)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
HttpContent | content | The request contents. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
PutAsync(string, HttpContent, CancellationToken)
Performs a PUT request.
Declaration
public Task<HttpResponseMessage> PutAsync(string requestUri, HttpContent content, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | requestUri | The request URI. |
HttpContent | content | The request contents. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
PutAsync(Uri, HttpContent)
Performs a PUT request.
Declaration
public Task<HttpResponseMessage> PutAsync(Uri requestUri, HttpContent content)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
HttpContent | content | The request contents. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
PutAsync(Uri, HttpContent, CancellationToken)
Performs a PUT request.
Declaration
public Task<HttpResponseMessage> PutAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The request URI. |
HttpContent | content | The request contents. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
SendAsync(HttpRequestMessage)
Sends a request.
Declaration
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request)
Parameters
Type | Name | Description |
---|---|---|
HttpRequestMessage | request | The request. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
SendAsync(HttpRequestMessage, HttpCompletionOption)
Sends a request.
Declaration
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption)
Parameters
Type | Name | Description |
---|---|---|
HttpRequestMessage | request | The request. |
HttpCompletionOption | completionOption | The completion option. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)
Sends a request.
Declaration
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
HttpRequestMessage | request | The request. |
HttpCompletionOption | completionOption | The completion option. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
SendAsync(HttpRequestMessage, CancellationToken)
Sends a request.
Declaration
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
HttpRequestMessage | request | The request. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |