Esempio n. 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);
            }
        }
Esempio n. 5
0
        public unsafe void ReadHeaderName_InvalidHeaderLine_ThrowsHttpRequestException(string headerLine)
        {
            byte[] buffer = headerLine.Select(c => checked ((byte)c)).ToArray();

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

                string headerName;
                string headerValue;

                Assert.Throws <HttpRequestException>(() => reader.ReadHeader(out headerName, out headerValue));
            }
        }
        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);
            }
        }
Esempio n. 7
0
        public unsafe void ReadHeader_ValidHeaderLine_HeaderReturned(string headerLine, string expectedHeaderName, string expectedHeaderValue)
        {
            byte[] buffer = headerLine.Select(c => checked ((byte)c)).ToArray();
            fixed(byte *pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked ((ulong)buffer.Length));

                string headerName;
                string headerValue;

                Assert.True(reader.ReadHeader(out headerName, out headerValue));
                Assert.Equal(expectedHeaderName, headerName);
                Assert.Equal(expectedHeaderValue, headerValue);
            }
        }
Esempio n. 8
0
        public unsafe void ReadHeader_EmptyBuffer_ReturnsFalse()
        {
            byte[] buffer = new byte[2]; // Non-empty array so we can get a valid pointer using fixed.
            ulong  length = 0;           // But a length of 0 for empty.

            fixed(byte *pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), length);

                string headerName;
                string headerValue;

                Assert.False(reader.ReadHeader(out headerName, out headerValue));
                Assert.Null(headerName);
                Assert.Null(headerValue);
            }
        }
        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);
            }
        }
        public unsafe void ReadHeaderName_InvalidHeaderLine_ThrowsHttpRequestException(string headerLine)
        {
            byte[] buffer = headerLine.Select(c => checked((byte)c)).ToArray();

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

                string headerName;
                string headerValue;
                Assert.Throws<HttpRequestException>(() => reader.ReadHeader(out headerName, out headerValue));
            }
        }
        public unsafe void ReadHeader_EmptyBuffer_ReturnsFalse()
        {
            byte[] buffer = new byte[2]; // Non-empty array so we can get a valid pointer using fixed.
            ulong length = 0; // But a length of 0 for empty.

            fixed (byte* pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), length);

                string headerName;
                string headerValue;
                Assert.False(reader.ReadHeader(out headerName, out headerValue));
                Assert.Null(headerName);
                Assert.Null(headerValue);
            }
        }
        public unsafe void ReadHeader_ValidHeaderLine_HeaderReturned(string expectedHeaderName, string expectedHeaderValue, bool spaceAfterColon)
        {
            string headerLine = $"{expectedHeaderName}:{(spaceAfterColon ? " " : "")}{expectedHeaderValue}";

            byte[] buffer = headerLine.Select(c => checked((byte)c)).ToArray();

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

                string headerName;
                string headerValue;
                Assert.True(reader.ReadHeader(out headerName, out headerValue));
                Assert.Equal(expectedHeaderName, headerName);
                Assert.Equal(expectedHeaderValue, headerValue);
            }
        }