Class HttpExecutable
This class sends requests encoded through HttpRequest objects using an HttpClient retrieved via Target<T>(). The results are wrapped in HttpResponse objects and returned to the caller.
public class HttpExecutable
- Inheritance
-
HttpExecutable
- Inherited Members
Constructors
HttpExecutable()
Constructs an instance of this class, taking in an optional pair of payload serializer and deserializer lambdas.
public HttpExecutable()
Properties
Default
Returns the default instance of this class.
The default instance serializes payloads using JsonSerializer class, encoded as a UTF8 string with ContentType set to 'application/json'.
The default instance deserializes the payload assuming the string is encoded as a JSON object. It uses JsonSerializer to deserialize the payload, treating property names as case insensitive.
public static HttpExecutable Default { get; set; }
Property Value
EmitCorrelationId
Indicates whether correlation id should be emitted in HTTP diagnostic logs. Correlation Ids can be particularly helpful when debugging logs of requests made concurrently with each other.
public bool EmitCorrelationId { get; set; }
Property Value
EmitDiagnosticLogs
This flag controls whether this class emits diagnostic logs when executing HTTP requests.
public bool EmitDiagnosticLogs { get; set; }
Property Value
LogLineEmitter
This classes uses this lambda to emit log lines.
public Action<string> LogLineEmitter { get; set; }
Property Value
MaxLogLineLength
The maximum length of a log line after which it is trimmed. Defaults to 2KB.
public int MaxLogLineLength { get; set; }
Property Value
PayloadDeserializer
The payload deserializer takes in a string read from the HttpResponseMessage object along with the expected type of the response and returns a deserialized object.
public Func<HttpContent, Type, object> PayloadDeserializer { get; set; }
Property Value
PayloadSerializer
The payload serializer takes in an object and returns a StringContent object which is used to pass the payload as the body in an HttpRequestMessage object.
public Func<object, HttpContent> PayloadSerializer { get; set; }
Property Value
TrimLogLinesIfTooLong
Whether to trim log lines if there length exceeds MaxLogLineLength
public bool TrimLogLinesIfTooLong { get; set; }
Property Value
Methods
BytesToHigherUnits(long)
public static string BytesToHigherUnits(long numBytes)
Parameters
numByteslong
Returns
ExecuteAsync(TestingContext, HttpRequest, Dictionary<string, string>)
This method takes an http request with no payload and returns an http response with no payload.
public Task<HttpResponse> ExecuteAsync(TestingContext context, HttpRequest httpRequest, Dictionary<string, string> additionalRequestHeaders = null)
Parameters
contextTestingContexthttpRequestHttpRequestadditionalRequestHeadersDictionary<string, string>
Returns
ExecuteAsync<TEmpty, TResponse>(TestingContext, HttpRequest, Func<int, bool>, Dictionary<string, string>)
This method takes an http request with no payload and returns an http response containing a payload of type TResponse.
public Task<HttpResponse<TResponse>> ExecuteAsync<TEmpty, TResponse>(TestingContext context, HttpRequest httpRequest, Func<int, bool> shouldParsePayload = null, Dictionary<string, string> additionalRequestHeaders = null) where TEmpty : Unit
Parameters
contextTestingContexthttpRequestHttpRequestshouldParsePayloadFunc<int, bool>additionalRequestHeadersDictionary<string, string>
Returns
- Task<HttpResponse<TResponse>>
Type Parameters
TEmptyTResponse
ExecuteAsync<TRequest, TEmpty>(TestingContext, HttpRequest<TRequest>, Dictionary<string, string>)
This method takes an http request with a payload of type TRequest and returns an http response without any payload.
public Task<HttpResponse> ExecuteAsync<TRequest, TEmpty>(TestingContext context, HttpRequest<TRequest> httpRequest, Dictionary<string, string> additionalRequestHeaders = null) where TEmpty : Unit
Parameters
contextTestingContexthttpRequestHttpRequest<TRequest>additionalRequestHeadersDictionary<string, string>
Returns
Type Parameters
TRequestTEmpty
ExecuteAsync<TRequest, TResponse>(TestingContext, HttpRequest<TRequest>, Func<int, bool>, Dictionary<string, string>)
This method takes an http request with a payload of type TRequest and returns an http response containing a payload of type TResponse.
public Task<HttpResponse<TResponse>> ExecuteAsync<TRequest, TResponse>(TestingContext context, HttpRequest<TRequest> httpRequest, Func<int, bool> shouldParsePayload = null, Dictionary<string, string> additionalRequestHeaders = null)
Parameters
contextTestingContexthttpRequestHttpRequest<TRequest>shouldParsePayloadFunc<int, bool>additionalRequestHeadersDictionary<string, string>
Returns
- Task<HttpResponse<TResponse>>
Type Parameters
TRequestTResponse