public void op_Read_TextReader_whenGet()
        {
            var         request     = new HttpRequest();
            RequestLine requestLine = "GET / HTTP/1.1";
            HttpHeader  host        = "Host: www.example.com";
            HttpHeader  connection  = "Connection: close";

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine(requestLine);
                    writer.WriteLine(host);
                    writer.WriteLine(connection);
                    writer.WriteLine(string.Empty);
                    writer.WriteLine("body");
                    writer.Flush();
                    stream.Position = 0;
                    using (var reader = new StreamReader(stream))
                    {
                        request.Read(reader);
                    }
                }
            }

            Assert.Equal(requestLine, request.RequestLine);

            Assert.Equal(2, request.Headers.Count);
            Assert.True(request.Headers.Contains(host));
            Assert.True(request.Headers.Contains(connection));

            Assert.Null(request.Body);
        }
        public void op_FromString_string_whenGetRelative()
        {
            var expected = new RequestLine("GET", "/", "HTTP/1.1");
            var actual   = RequestLine.FromString("GET / HTTP/1.1");

            Assert.Equal(expected, actual);
        }
Example #3
0
        public void op_FromString_string_whenGetRelative()
        {
            var expected = new RequestLine("GET", "/", "HTTP/1.1");
            var actual = RequestLine.FromString("GET / HTTP/1.1");

            Assert.Equal(expected, actual);
        }
Example #4
0
        public void opImplicit_RequestLine_string()
        {
            var expected = new RequestLine("GET", "/", "HTTP/1.1");
            RequestLine actual = "GET / HTTP/1.1";

            Assert.Equal(expected, actual);
        }
        public void opImplicit_RequestLine_string()
        {
            var         expected = new RequestLine("GET", "/", "HTTP/1.1");
            RequestLine actual   = "GET / HTTP/1.1";

            Assert.Equal(expected, actual);
        }
        public void op_ToString()
        {
            const string expected = "HEAD / HTTP/1.1";
            var          actual   = new RequestLine("HEAD", "/", "HTTP/1.1").ToString();

            Assert.Equal(expected, actual);
        }
        public void op_Read_TextReader_whenPost()
        {
            var         request       = new HttpRequest();
            RequestLine requestLine   = "POST / HTTP/1.1";
            HttpHeader  contentLength = "Content-Length: 4";
            HttpHeader  contentType   = "Content-Type: text/plain; charset=UTF-8";
            HttpHeader  host          = "Host: www.example.com";
            HttpHeader  connection    = "Connection: keep-alive";

            try
            {
                var locator = new Mock <IServiceLocator>();
                locator
                .Setup(e => e.GetInstance <IMediaType>("text/plain"))
                .Returns(new TextPlain())
                .Verifiable();

                ServiceLocator.SetLocatorProvider(() => locator.Object);

                using (var stream = new MemoryStream())
                {
                    using (var writer = new StreamWriter(stream))
                    {
                        writer.WriteLine(requestLine);
                        writer.WriteLine(contentLength);
                        writer.WriteLine(contentType);
                        writer.WriteLine(host);
                        writer.WriteLine(connection);
                        writer.WriteLine(string.Empty);
                        writer.Write("text");
                        writer.Flush();
                        stream.Position = 0;
                        using (var reader = new StreamReader(stream))
                        {
                            request.Read(reader);
                        }
                    }
                }

                locator.VerifyAll();
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(null);
            }

            Assert.Equal(requestLine, request.RequestLine);

            Assert.Equal(4, request.Headers.Count);
            Assert.True(request.Headers.Contains(contentLength));
            Assert.True(request.Headers.Contains(contentType));
            Assert.True(request.Headers.Contains(host));
            Assert.True(request.Headers.Contains(connection));

            Assert.Equal("text", ((TextPlain)request.Body).Value);
        }
Example #8
0
        public override void Read(TextReader reader)
        {
            if (null == reader)
            {
                throw new ArgumentNullException("reader");
            }

            RequestLine = reader.ReadLine();
            base.Read(reader);
        }
        public void op_FromString_string_whenPost()
        {
            RequestLine requestLine   = "POST / HTTP/1.1";
            HttpHeader  contentLength = "Content-Length: 4";
            HttpHeader  contentType   = "Content-Type: text/plain; charset=UTF-8";
            HttpHeader  host          = "Host: www.example.com";
            HttpHeader  connection    = "Connection: keep-alive";

            var value = new StringBuilder();

            value.AppendLine(requestLine);
            value.AppendLine(contentLength);
            value.AppendLine(contentType);
            value.AppendLine(host);
            value.AppendLine(connection);
            value.AppendLine(string.Empty);
            value.Append("text");

            HttpRequest obj;

            try
            {
                var locator = new Mock <IServiceLocator>();
                locator
                .Setup(e => e.GetInstance <IMediaType>("text/plain"))
                .Returns(new TextPlain())
                .Verifiable();

                ServiceLocator.SetLocatorProvider(() => locator.Object);

                obj = HttpRequest.FromString(value.ToString());

                locator.VerifyAll();
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(null);
            }

            Assert.Equal <string>(requestLine, obj.RequestLine);

            Assert.True(obj.Headers.Contains(contentLength));
            Assert.True(obj.Headers.Contains(contentType));
            Assert.True(obj.Headers.Contains(host));
            Assert.True(obj.Headers.Contains(connection));
        }
        public void prop_RequestLine_get()
        {
            RequestLine expected = "GET / HTTP/1.1";

            var mock = new Mock <IHttpRequest>();

            mock
            .SetupGet(x => x.RequestLine)
            .Returns(expected)
            .Verifiable();

            var actual = mock.Object.RequestLine;

            Assert.Same(expected, actual);

            mock.VerifyAll();
        }
Example #11
0
        public void op_FromString_string_whenGet()
        {
            RequestLine requestLine = "GET / HTTP/1.1";
            HttpHeader  host        = "Host: www.example.com";
            HttpHeader  connection  = "Connection: close";

            var value = new StringBuilder();

            value.AppendLine(requestLine);
            value.AppendLine(host);
            value.AppendLine(connection);

            var obj = HttpRequest.FromString(value.ToString());

            Assert.Equal <string>(requestLine, obj.RequestLine);

            Assert.True(obj.Headers.Contains(host));
            Assert.True(obj.Headers.Contains(connection));
        }
Example #12
0
        public override void Read(TextReader reader)
        {
            if (null == reader)
            {
                throw new ArgumentNullException("reader");
            }

            RequestLine = reader.ReadLine();
            base.Read(reader);
        }
Example #13
0
 public void op_FromString_string_whenMissingRequestUri()
 {
     Assert.Throws <FormatException>(() => RequestLine.FromString("GET HTTP/1.1"));
 }
Example #14
0
 public void op_FromString_string_whenMissingHttpVersion()
 {
     Assert.Throws <FormatException>(() => RequestLine.FromString("GET /"));
 }
Example #15
0
 public void op_FromString_string_whenMissingHttpMethod()
 {
     Assert.Throws <FormatException>(() => RequestLine.FromString("/ HTTP/1.1"));
 }
Example #16
0
 public void op_FromString_string_whenLR()
 {
     Assert.Throws <FormatException>(() => RequestLine.FromString("999 Foo \n Bar"));
 }
Example #17
0
 public void op_FromString_stringNull()
 {
     Assert.Throws <ArgumentNullException>(() => RequestLine.FromString(null));
 }
Example #18
0
 public void op_FromString_stringEmpty()
 {
     Assert.Throws <FormatException>(() => RequestLine.FromString(string.Empty));
 }
Example #19
0
        public void op_ToString()
        {
            const string expected = "HEAD / HTTP/1.1";
            var actual = new RequestLine("HEAD", "/", "HTTP/1.1").ToString();

            Assert.Equal(expected, actual);
        }