public void PathWithQuery_WithNullPathAndQuery_ReturnsNull()
        {
            var request = new ProviderServiceRequest();

            var uri = request.PathWithQuery();

            Assert.Null(uri);
        }
        public void PathWithQuery_WithJustQuery_ThrowsInvalidOperationException()
        {
            var request = new ProviderServiceRequest
            {
                Query = "test1=1&test2=2"
            };

            Assert.Throws <InvalidOperationException>(() => request.PathWithQuery());
        }
        public void PathWithQuery_WithJustPath_ReturnsPath()
        {
            var request = new ProviderServiceRequest
            {
                Path = "/events"
            };

            var uri = request.PathWithQuery();

            Assert.Equal(request.Path, uri);
        }
예제 #4
0
        public HttpRequestMessage Convert(ProviderServiceRequest from)
        {
            if (from == null)
            {
                return(null);
            }

            var requestHttpMethod = _httpMethodMapper.Convert(from.Method);
            var requestPath       = from.PathWithQuery();

            var to = new HttpRequestMessage(requestHttpMethod, requestPath);

            var contentRelatedHeaders = new Dictionary <string, string>();

            if (from.Headers != null && from.Headers.Any())
            {
                foreach (var requestHeader in from.Headers)
                {
                    //Strip any Content- headers as they need to be attached to Request content when using a HttpRequestMessage
                    if (requestHeader.Key.IndexOf("Content-", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        contentRelatedHeaders.Add(requestHeader.Key, requestHeader.Value);
                        continue;
                    }

                    to.Headers.Add(requestHeader.Key, requestHeader.Value);
                }
            }

            if (from.Body != null)
            {
                HttpBodyContent bodyContent = _httpBodyContentMapper.Convert(body: from.Body, headers: from.Headers);
                var             httpContent = _httpContentMapper.Convert(bodyContent);

                //Set the content related headers
                if (httpContent != null && contentRelatedHeaders.Any())
                {
                    foreach (var contentHeader in contentRelatedHeaders)
                    {
                        if (contentHeader.Key.Equals("Content-Type", StringComparison.InvariantCultureIgnoreCase) &&
                            httpContent.Headers.Any(x => x.Key.Equals("Content-Type", StringComparison.InvariantCultureIgnoreCase)))
                        {
                            continue;
                        }

                        httpContent.Headers.Add(contentHeader.Key, contentHeader.Value);
                    }
                }

                to.Content = httpContent;
            }

            return(to);
        }
        public void PathWithQuery_WithPathAndQuery_ReturnsPathWithQuery()
        {
            var request = new ProviderServiceRequest
            {
                Path  = "/events",
                Query = "test1=1&test2=2"
            };

            var uri = request.PathWithQuery();

            Assert.Equal(request.Path + "?" + request.Query, uri);
        }
        public HttpRequestMessage Convert(ProviderServiceRequest from)
        {
            if (from == null)
            {
                return(null);
            }

            var requestHttpMethod = _httpMethodMapper.Convert(from.Method);
            var requestPath       = from.PathWithQuery();

            var to = new HttpRequestMessage(requestHttpMethod, requestPath);

            if (from.Headers != null && from.Headers.Any())
            {
                foreach (var requestHeader in from.Headers)
                {
                    //TODO: Check if there are any other headers which need special treatment
                    //Handle the content-type header as little differently, as they need to be attached to the content when using a HttpRequestMessage
                    //Strip the Content-Length header as is automatically attached to the request
                    if (requestHeader.Key.Equals("Content-Type", StringComparison.InvariantCultureIgnoreCase) ||
                        requestHeader.Key.Equals("Content-Length", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    to.Headers.Add(requestHeader.Key, requestHeader.Value);
                }
            }

            if (from.Body != null)
            {
                HttpBodyContent bodyContent = _httpBodyContentMapper.Convert(from.Body, from.Headers);
                to.Content = _httpContentMapper.Convert(bodyContent);
            }

            return(to);
        }