示例#1
0
        internal ContentType ExtractContentTypeFromResponse(IHttpWebResponse response)
        {
            ContentType result;

            if (HttpConverter.TryParseContentType(response.ContentType, out result))
            {
                return(result);
            }

            var headers = response.Headers;
            const ContentType fallback = ContentType.ApplicationJson;

            if (headers == null)
            {
                return(fallback);
            }

            var contentTypeHeader = headers[HttpResponseHeader.ContentType];

            if (contentTypeHeader == null)
            {
                return(fallback);
            }

            var contentType = HttpConverter.ContentType(contentTypeHeader);

            return(contentType);
        }
        public void ShouldRetrunFalseIfStringCantBeParsedAsContentType(string contentTypeString)
        {
            /* Setup */
            ContentType contentType;

            /* Test */
            var result = HttpConverter.TryParseContentType(contentTypeString, out contentType);

            /* Assert */
            Assert.That(result, Is.False);
        }