Exemple #1
0
        public unsafe void ReadStatusLine_ValidStatusCodeLine_ResponseMessageVersionSet(string statusLine, int major, int minor)
        {
            byte[] buffer = statusLine.Select(c => checked ((byte)c)).ToArray();

            fixed(byte *pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked ((ulong)buffer.Length));

                using (var response = new HttpResponseMessage())
                {
                    Assert.True(reader.ReadStatusLine(response));
                    int expectedMajor = 0;
                    int expectedMinor = 0;
                    if (major == 1 && (minor == 0 || minor == 1))
                    {
                        expectedMajor = 1;
                        expectedMinor = minor;
                    }
                    else if (major == 2 && minor == 0)
                    {
                        expectedMajor = 2;
                        expectedMinor = 0;
                    }

                    Assert.Equal(expectedMajor, response.Version.Major);
                    Assert.Equal(expectedMinor, response.Version.Minor);
                }
            }
        }
        public unsafe void ReadStatusLine_InvalidStatusCode_ThrowsHttpRequestException(string statusLine, HttpStatusCode expectedCode, string phrase)
        {
            byte[] buffer = statusLine.Select(c => checked((byte)c)).ToArray();

            fixed (byte* pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked((ulong)buffer.Length));
                var response = new HttpResponseMessage();
                Assert.Throws<HttpRequestException>(() => reader.ReadStatusLine(response));
            }
        }
        public unsafe void ReadStatusLine_InvalidStatusCode_ThrowsHttpRequestException(string statusLine, HttpStatusCode expectedCode, string phrase)
        {
            byte[] buffer = statusLine.Select(c => checked ((byte)c)).ToArray();

            fixed(byte *pBuffer = buffer)
            {
                var reader   = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked ((ulong)buffer.Length));
                var response = new HttpResponseMessage();

                Assert.Throws <HttpRequestException>(() => reader.ReadStatusLine(response));
            }
        }
        public unsafe void ReadStatusLine_ValidStatusCode_ResponseMessageValueSet(string statusLine, HttpStatusCode expectedCode, string expectedPhrase)
        {
            byte[] buffer = statusLine.Select(c => checked((byte)c)).ToArray();

            fixed (byte* pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked((ulong)buffer.Length));
                var response = new HttpResponseMessage();
                Assert.True(reader.ReadStatusLine(response));
                Assert.Equal(expectedCode, response.StatusCode);
                Assert.Equal(expectedPhrase, response.ReasonPhrase);
            }
        }
        public unsafe void ReadStatusLine_ValidStatusCode_ResponseMessageValueSet(string statusLine, HttpStatusCode expectedCode, string expectedPhrase)
        {
            byte[] buffer = statusLine.Select(c => checked ((byte)c)).ToArray();

            fixed(byte *pBuffer = buffer)
            {
                var reader   = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked ((ulong)buffer.Length));
                var response = new HttpResponseMessage();

                Assert.True(reader.ReadStatusLine(response));
                Assert.Equal(expectedCode, response.StatusCode);
                Assert.Equal(expectedPhrase, response.ReasonPhrase);
            }
        }
        public unsafe void ReadStatusLine_ValidStatusCodeLine_ResponseMessageVersionSet(string statusLine, int major, int minor)
        {
            byte[] buffer = statusLine.Select(c => checked((byte)c)).ToArray();

            fixed (byte* pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked((ulong)buffer.Length));
                var response = new HttpResponseMessage();
                Assert.True(reader.ReadStatusLine(response));
                int expectedMajor = 0;
                int expectedMinor = 0;
                if (major == 1 && (minor == 0 || minor == 1))
                {
                    expectedMajor = 1;
                    expectedMinor = minor;
                }

                Assert.Equal(expectedMajor, response.Version.Major);
                Assert.Equal(expectedMinor, response.Version.Minor);
            }
        }