public void ReadAsHttpResponseMessageAsync_ResponseWithEntity_ShouldReturnHttpResponseMessage()
        {
            HttpContent         content      = CreateContent(isRequest: false, hasEntity: true);
            HttpResponseMessage httpResponse = content.ReadAsHttpResponseMessageAsync().Result;

            ValidateResponseMessage(httpResponse, hasEntity: true);
        }
Пример #2
0
        public async Task ReadAsHttpResponseMessageAsync_ResponseWithEntity_ShouldReturnHttpResponseMessage()
        {
            HttpContent         content      = CreateContent(isRequest: false, hasEntity: true);
            HttpResponseMessage httpResponse = await content.ReadAsHttpResponseMessageAsync();

            await ValidateResponseMessageAsync(httpResponse, hasEntity : true);
        }
        public void ReadAsHttpResponseMessageAsync_Asp_ShouldBeDeserializedCorrectly()
        {
            string[] response = new string[] {
                @"HTTP/1.1 302 Found",
                @"Proxy-Connection: Keep-Alive",
                @"Connection: Keep-Alive",
                @"Content-Length: 124",
                @"Via: 1.1 RED-PRXY-23",
                @"Date: Thu, 30 Jun 2011 00:16:35 GMT",
                @"Location: /en-us/",
                @"Content-Type: text/html; charset=utf-8",
                @"Server: Microsoft-IIS/7.5",
                @"Cache-Control: private",
                @"P3P: CP=""ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI""",
                @"Set-Cookie: A=I&I=AxUFAAAAAAD7BwAA8Jx0njhGoW3MGASDmzeaGw!!&M=1; domain=.microsoft.com; expires=Sun, 30-Jun-2041 00:16:35 GMT; path=/",
                @"Set-Cookie: ADS=SN=175A21EF; domain=.microsoft.com; path=/",
                @"Set-Cookie: Sto.UserLocale=en-us; path=/",
                @"X-AspNetMvc-Version: 3.0",
                @"X-AspNet-Version: 4.0.30319",
                @"X-Powered-By: ASP.NET",
                @"Set-Cookie: A=I&I=AxUFAAAAAAD7BwAA8Jx0njhGoW3MGASDmzeaGw!!&M=1; domain=.microsoft.com; expires=Sun, 30-Jun-2041 00:16:35 GMT; path=/; path=/",
                @"Set-Cookie: ADS=SN=175A21EF; domain=.microsoft.com; path=/; path=/",
                @"P3P: CP=""ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI""",
                @"X-Powered-By: ASP.NET",
            };
            string expectedEntity = @"<html><head><title>Object moved</title></head><body><h2>Object moved to <a href=""/en-us/"">here</a>.</h2></body></html>";

            HttpContent         content      = CreateContent(false, response, expectedEntity);
            HttpResponseMessage httpResponse = content.ReadAsHttpResponseMessageAsync().Result;

            Assert.True(httpResponse.Headers.Contains("x-powered-by"));
            string actualEntity = httpResponse.Content.ReadAsStringAsync().Result;

            Assert.Equal(expectedEntity, actualEntity);
        }
        public void ReadAsHttpResponseMessageAsync_LargeHeaderSize()
        {
            string[] response = new[] {
                @"HTTP/1.1 200 OK",
                String.Format("Set-Cookie: {0}={1}", new String('a', 16 * 1024), new String('b', 16 * 1024))
            };

            HttpContent         content      = CreateContent(false, response, "sample body");
            HttpResponseMessage httpResponse = content.ReadAsHttpResponseMessageAsync(64 * 1024, 64 * 1024).Result;
        }
        public void ReadAsHttpResponseMessageAsync_Throws_TheHeaderSizeExceededTheDefaultLimit()
        {
            string[] response = new[] {
                @"HTTP/1.1 200 OK",
                String.Format("Set-Cookie: {0}={1}", new String('a', 16 * 1024), new String('b', 16 * 1024))
            };

            Assert.Throws <InvalidOperationException>(() =>
            {
                HttpContent content = CreateContent(false, response, "sample body");
                HttpResponseMessage httpResponse = content.ReadAsHttpResponseMessageAsync().Result;
            });
        }
        public void RoundtripServerResponse(IEnumerable <string> message)
        {
            HttpContent         content            = CreateContent(false, message, @"<html><head><title>Object moved</title></head><body><h2>Object moved to <a href=""/en-us/"">here</a>.</h2></body></html>");
            HttpResponseMessage httpResponse       = content.ReadAsHttpResponseMessageAsync().Result;
            HttpMessageContent  httpMessageContent = new HttpMessageContent(httpResponse);

            MemoryStream destination = new MemoryStream();

            httpMessageContent.CopyToAsync(destination).Wait();
            destination.Seek(0, SeekOrigin.Begin);
            string destinationMessage = new StreamReader(destination).ReadToEnd();
            string sourceMessage      = content.ReadAsStringAsync().Result;

            Assert.Equal(sourceMessage, destinationMessage);
        }
        public void ReadAsHttpResponseMessageAsync_SortHeaders()
        {
            string[] response = new[] {
                @"HTTP/1.1 200 OK",
                @"Content-Language: xx",
                @"Response-Header: zz",
            };

            HttpContent         content      = CreateContent(false, response, "sample body");
            HttpResponseMessage httpResponse = content.ReadAsHttpResponseMessageAsync().Result;

            Assert.Equal("xx", httpResponse.Content.Headers.ContentLanguage.ToString());

            IEnumerable <string> ResponseHeaderValues;

            Assert.True(httpResponse.Headers.TryGetValues("Response-header", out ResponseHeaderValues));
            Assert.Equal("zz", ResponseHeaderValues.First());
        }