public static HttpMessageModel ToModel(this HttpResponseMessage response) { var result = new HttpMessageModel(); result.StatusCode = (int)(response.StatusCode); result.Data = response.Content.ReadAsStringAsync().Result; result.Headers = new Dictionary <string, string[]>(); foreach (var header in response.Headers) { result.Headers.Add(header.Key, header.Value.ToArray()); } result.ApiCall = null; try { result.BadModel = JsonConvert.DeserializeObject <BadModelResponse>( result.Data as string); } catch (Exception) { result.BadModel = null; } return(result); }
public static void PatchWithPort(this HttpMessageModel request, int port) { request.ApiCall.Path.BasePath = String.Format( BaseUrlTemplate, port, request.ApiCall.Path.BasePath ); }
public static void AddApiPath( this HttpMessageModel request, HttpMethod method, string basePath, string additionalApiPath = null) { request.ApiCall = Test.Extensions.UpdateIfNull(request.ApiCall, new ApiCallModel()); request.ApiCall.Method = Test.Extensions.UpdateIfNull(request.ApiCall.Method, method); request.ApiCall.Path = Test.Extensions.UpdateIfNull(request.ApiCall.Path, new ApiPathModel()); request.ApiCall.Path.BasePath = Test.Extensions.UpdateIfNull(request.ApiCall.Path.BasePath, basePath); request.ApiCall.Path.AdditionalPath = Test.Extensions.UpdateIfNull(request.ApiCall.Path.AdditionalPath, additionalApiPath ?? String.Empty); }
public static HttpRequestMessage ToRequest(this HttpMessageModel requestInfo) { HttpRequestMessage request = new HttpRequestMessage(); if (requestInfo.Data != null) { request.Content = requestInfo.Data.ToHttpContent(); } if (requestInfo.Headers != null) { foreach (var header in requestInfo.Headers) { request.Headers.Add(header.Key, header.Value); } } request.Method = requestInfo.ApiCall.Method; request.RequestUri = new Uri(requestInfo.ApiCall.Path.ToString()); return(request); }
public HttpResponseMessage Send(HttpMessageModel requestInfo) => Send(requestInfo.ToRequest());