Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 internal ControllerCallResult(
     HttpResponseMessage httpResponseMessage,
     string resultAsString,
     HttpStatusCode statusCode,
     IRidgeSerializer serializer) : base(httpResponseMessage, resultAsString, statusCode)
 {
     _serializer = serializer;
 }
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 5
0
        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}");
        }
Exemplo n.º 6
0
 public ResultFactoryForController(
     IRidgeSerializer serializer)
 {
     _serializer = serializer;
 }