Class Handler
An asynchronous function that handles HTTP requests to simulate the desired server behavior in tests.
Inheritance
System.Object
Handler
Namespace: LaunchDarkly.TestHelpers.HttpTest
Assembly: LaunchDarkly.TestHelpers.dll
Syntax
public sealed class Handler : MulticastDelegate
Remarks
Use the factory methods in Handlers to create standard implementations. There are two ways to use these handlers:
- In end-to-end HTTP testing against an HttpServer. This provides the most realistic operating conditions for your HTTP client test code, since it will do actual HTTP and can be accessed by an external client without any customization of the client other than specifying the target URI.
- To simulate responses from an
HttpClient
using a customHttpMessageHandler
that does not make any network requests. In this case, you can configure your handler(s) just the same, but use AsMessageHandler(Handler) to convert the result into anHttpMessageHandler
that can be used in anHttpClient
. This can be useful in testing code that makes requests to a real external URI, redirecting it to your internal fixture. It also allows simulating network errors; see Error(Exception).
In either use case, there is always a single handler that represents the server as a whole. If you want to apply the effects of multiple handles to the same response, use Then(Handler, Handler). If you want the server to return different responses for different requests, use combinators such as Sequential(Handler[]) or Router(out SimpleRouter).
Constructors
Handler(Object, IntPtr)
Declaration
public Handler(object object, IntPtr method)
Parameters
Type | Name | Description |
---|---|---|
System.Object | object | |
System.IntPtr | method |
Methods
BeginInvoke(IRequestContext, AsyncCallback, Object)
Declaration
public virtual IAsyncResult BeginInvoke(IRequestContext context, AsyncCallback callback, object object)
Parameters
Type | Name | Description |
---|---|---|
IRequestContext | context | |
System.AsyncCallback | callback | |
System.Object | object |
Returns
Type | Description |
---|---|
System.IAsyncResult |
EndInvoke(IAsyncResult)
Declaration
public virtual Task EndInvoke(IAsyncResult result)
Parameters
Type | Name | Description |
---|---|---|
System.IAsyncResult | result |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Invoke(IRequestContext)
Declaration
public virtual Task Invoke(IRequestContext context)
Parameters
Type | Name | Description |
---|---|---|
IRequestContext | context |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |