public void TestBasicWebRequest()
        {
            var builder = new RequestBuilder()
                {
                    BaseUri = new Uri("http://www.example.com/")
                };

            var request = builder.CreateRequest();
            Assert.That(request.Method, Is.EqualTo(HttpMethod.Get));
            Assert.That(request.RequestUri, Is.EqualTo(new Uri("http://www.example.com/")));
        }
        public void TestBasePlusPathMath()
        {
            var builder = new RequestBuilder()
                {
                    BaseUri = new Uri("http://www.example.com/"),
                    Path = "test/path",
                    Method = "PUT"
                };

            var request = builder.CreateRequest();
            Assert.That(request.Method, Is.EqualTo(HttpMethod.Put));
            Assert.That(request.RequestUri, Is.EqualTo(new Uri("http://www.example.com/test/path")));
        }
        public void TestMultipleQueryParameter()
        {
            var builder = new RequestBuilder()
            {
                BaseUri = new Uri("http://www.example.com/"),
            };
            builder.AddParameter(RequestParameterType.Query, "testQueryParamA", "testValueA");
            builder.AddParameter(RequestParameterType.Query, "testQueryParamB", "testValueB");

            var request = builder.CreateRequest();
            Assert.That(request.RequestUri, Is.EqualTo(
                new Uri("http://www.example.com/?testQueryParamA=testValueA&testQueryParamB=testValueB")));
        }
        public void TestPathParameterWithUrlEncode()
        {
            var builder = new RequestBuilder()
                {
                    BaseUri = new Uri("http://www.example.com/"),
                    Path = "test/{id}",
                };

            builder.AddParameter(RequestParameterType.Path, "id", " %va/ue");

            var request = builder.CreateRequest();
            Assert.That(request.RequestUri, Is.EqualTo(new Uri("http://www.example.com/test/%20%25va%2Fue")));
        }
        public void TestInvalidPathParameters()
        {
            // A path parameter is missing.
            var builder = new RequestBuilder()
            {
                BaseUri = new Uri("http://www.example.com/"),
                Path = "test/{id}/foo/bar",
            };
            Assert.Throws<ArgumentException>(() =>
                {
                    builder.CreateRequest();
                });

            // Invalid number after ':' in path parameter.
            builder = new RequestBuilder()
            {
                BaseUri = new Uri("http://www.example.com/"),
                Path = "test/{id:SHOULD_BE_NUMBER}/foo/bar",
            };
            builder.AddParameter(RequestParameterType.Path, "id", "hello");
            Assert.Throws<ArgumentException>(() =>
            {
                builder.CreateRequest();
            });
        }
        public void TestPathParameter()
        {
            var builder = new RequestBuilder()
                {
                    BaseUri = new Uri("http://www.example.com/"),
                    Path = "test/{id}/foo/bar",
                };

            builder.AddParameter(RequestParameterType.Path, "id", "value");

            var request = builder.CreateRequest();
            Assert.That(request.RequestUri, Is.EqualTo(new Uri("http://www.example.com/test/value/foo/bar")));
        }
        public void TestMultipleQueryParameters()
        {
            var builder = new RequestBuilder()
            {
                BaseUri = new Uri("http://www.example.com/"),
            };

            builder.AddParameter(RequestParameterType.Query, "q", "value1");
            builder.AddParameter(RequestParameterType.Query, "q", "value2");

            var request = builder.CreateRequest();
            Assert.That(request.RequestUri, Is.EqualTo(new Uri("http://www.example.com/?q=value1&q=value2")));
        }
        public void TestQueryParameterWithUrlEncode()
        {
            var builder = new RequestBuilder()
                {
                    BaseUri = new Uri("http://www.example.com/"),
                };

            builder.AddParameter(RequestParameterType.Query, "test Query Param", "test %va/ue");

            var request = builder.CreateRequest();
            Assert.That(request.RequestUri, Is.EqualTo(
                new Uri("http://www.example.com/?test%20Query%20Param=test%20%25va%2Fue")));
        }