Example #1
0
        public HttpRequestMessage CreateHttpRequestMessage <Tbody>(HttpApiMethodsType apiMethodName, string apiUrl, Tbody requestBody, List <CustomHeader> requestHeader = null)
        {
            //defense
            string apiMethod = HttpApiMethodsTypeConverter.EnumToString(apiMethodName);

            ValidateInputString(apiMethod);
            ValidateInputString(apiUrl);

            var request = new HttpRequestMessage(new HttpMethod(apiMethod), $"{apiUrl}");

            if (requestBody != null)
            {
                string output = JsonConvert.SerializeObject(requestBody);
                request.Content = new StringContent
                                  (
                    content: JsonConvert.SerializeObject(requestBody),
                    encoding: Encoding.UTF8,
                    mediaType: "application/json"
                                  );
            }

            if (requestHeader != null && requestHeader.Count > 0)
            {
                foreach (var item in requestHeader)
                {
                    request.Headers.Add(item.HeaderName, item.HeaderValue);
                }
            }

            return(request);
        }
 BaseApiSettings(string url, TRequest request, List <CustomHeader> header = null, HttpApiMethodsType apiMethodName = HttpApiMethodsType.POST, bool doNotDeserializeOutput = true, HttpAuth authorizationType = null)
 {
     Url                    = url;
     Request                = request;
     Header                 = header;
     ApiMethodName          = apiMethodName;
     DoNotDeserializeOutput = doNotDeserializeOutput;
     AuthRequest            = authorizationType;
 }
        public void Test_HttpApiMethodsTypeConverter_EnumToString_SuccessFullParse(HttpApiMethodsType methodName)
        {
            //Arrange

            //Act
            var result = HttpApiMethodsTypeConverter.EnumToString(methodName);


            //Arrange
            Assert.NotNull(result);
            Assert.IsType <string>(result);
        }
Example #4
0
        public static string EnumToString(HttpApiMethodsType methodType)
        {
            switch (methodType)
            {
            case HttpApiMethodsType.GET:
                return("GET");

            case HttpApiMethodsType.POST:
                return("POST");

            case HttpApiMethodsType.PUT:
                return("PUT");

            case HttpApiMethodsType.DELETE:
                return("DELETE");

            case HttpApiMethodsType.PATCH:
                return("PATCH");

            default:
                throw new InvalidEnumArgumentException($"Wrong method type: {methodType}");
            }
        }