public static HttpRequestMessage Create( string httpMethod, string url, object?contentData, Guid callId, string contentType, IDictionary <string, object?> headerParams, IRidgeSerializer serializer) { var httpMethodObject = new HttpMethod(httpMethod); var request = new HttpRequestMessage { RequestUri = new Uri(url, UriKind.RelativeOrAbsolute), Method = httpMethodObject, }; if (httpMethodObject == HttpMethod.Post || httpMethodObject == HttpMethod.Get || httpMethodObject == HttpMethod.Delete || httpMethodObject == HttpMethod.Put) { request.Content = CreateContent(contentType, contentData, serializer); } foreach (var headerParam in headerParams) { request.Headers.Add(headerParam.Key, headerParam.Value?.ToString()); } request.Headers.Add("ridgeCallId", callId.ToString()); return(request); }
internal ControllerCallResult( HttpResponseMessage httpResponseMessage, string resultAsString, HttpStatusCode statusCode, IRidgeSerializer serializer) : base(httpResponseMessage, resultAsString, statusCode) { _serializer = serializer; }
/// <summary> /// Create controller factory. /// </summary> /// <param name="httpClient"></param> /// <param name="serviceProvider">Service provider present in WebApplicationFactory.</param> /// <param name="logWriter"> /// Used to log requests and responses from server. /// Use <see cref="XunitLogWriter" /> or <see cref="NunitLogWriter" /> or implement custom <see cref="ILogWriter" /> /// </param> /// <param name="ridgeSerializer"> /// Serializer used to serialize and deserialize requests. /// Serializer is by default chosen based on asp.net settings. If you need custom serializer implement /// <see cref="IRidgeSerializer" />. /// </param> public ControllerFactory( HttpClient httpClient, IServiceProvider serviceProvider, ILogWriter?logWriter = null, IRidgeSerializer?ridgeSerializer = null) { _httpClient = httpClient; _serviceProvider = serviceProvider; _logWriter = logWriter; _serializer = SerializerProvider.GetSerializer(serviceProvider, ridgeSerializer); }
internal SendHttpRequestAsyncInterceptor( WebCaller webCaller, IGetInfo getInfo, IResultFactory resultFactory, ActionInfoTransformersCaller actionInfoTransformersCaller, IRidgeSerializer serializer, Action <MethodInfo>?methodValidation = null) { _webCaller = webCaller; _getInfo = getInfo; _resultFactory = resultFactory; _actionInfoTransformersCaller = actionInfoTransformersCaller; _serializer = serializer; _methodValidation = methodValidation; }
private static ByteArrayContent?CreateContent( string contentType, object?content, IRidgeSerializer serializer) { if (contentType == "application/json") { var serializedContent = serializer.Serialize(content); return(new StringContent(serializedContent !, Encoding.UTF8, contentType)); } if (contentType == "application/x-www-form-urlencoded") { var contentAsDictionary = GeneralHelpers.ToKeyValue(content); return(new FormUrlEncodedContent(contentAsDictionary !)); } throw new InvalidOperationException($"Unsupported content type {contentType}"); }
public ResultFactoryForController( IRidgeSerializer serializer) { _serializer = serializer; }