public void Should_safely_handle_multiple_calls_to_build_method()
        {
            var builder = new RequestUrlBuilder
            {
                "foo", "bar", "baz"
            };

            var url1 = builder.Build();
            var url2 = builder.Build();

            url2.Should().BeSameAs(url1);
        }
예제 #2
0
        public void BuildComplexUrl_Create()
        {
            string expected = String.Format("http://testprefix/foo/1/bar/List(foo,2,3)/baz/(deeper:List(found,it,{0}))/biz", complexStringEscapedPath);

            GreetingBuilder greetingBuilder = new GreetingBuilder()
            {
                id      = 555,
                tone    = new Tone(Tone.Symbol.INSULTING),
                message = "build URl for this CREATE"
            };
            Greeting greeting = greetingBuilder.Build();

            CreateRequestBuilder <int, Greeting> requestBuilder = new CreateRequestBuilder <int, Greeting>("foo/{one}/bar/{list}/baz/{complex}/biz");

            requestBuilder.SetPathKey("one", 1);
            requestBuilder.SetPathKey("list", new List <object>()
            {
                "foo", 2, 3
            });
            requestBuilder.SetPathKey("complex", new Dictionary <string, object>()
            {
                { "deeper", new List <object>()
                  {
                      "found", "it", complexString
                  } }
            });
            CreateRequest <int, Greeting> request = requestBuilder.Build();

            RequestUrlBuilder <CreateResponse <int, Greeting> > urlBuilder = new RequestUrlBuilder <CreateResponse <int, Greeting> >(request, "http://testprefix");
            Uri url = urlBuilder.Build();

            Assert.AreEqual(expected, url.AbsoluteUri);
        }
예제 #3
0
        public void BuildComplexUrl_Get()
        {
            string expected = String.Format("http://testprefix/foo/1/bar/List(foo,2,3)/baz/(deeper:List(found,it,{0}))/biz/123", complexStringEscapedPath);

            GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("foo/{one}/bar/{list}/baz/{complex}/biz");

            requestBuilder.SetID(123);
            requestBuilder.SetPathKey("one", 1);
            requestBuilder.SetPathKey("list", new List <object>()
            {
                "foo", 2, 3
            });
            requestBuilder.SetPathKey("complex", new Dictionary <string, object>()
            {
                { "deeper", new List <object>()
                  {
                      "found", "it", complexString
                  } }
            });
            GetRequest <int, Greeting> request = requestBuilder.Build();

            RequestUrlBuilder <EntityResponse <Greeting> > urlBuilder = new RequestUrlBuilder <EntityResponse <Greeting> >(request, "http://testprefix");
            Uri url = urlBuilder.Build();

            Assert.AreEqual(expected, url.AbsoluteUri);
        }
예제 #4
0
        public void BuildComplexUrl_Finder()
        {
            string expected = String.Format("http://testprefix/foo/1/bar/List(foo,2,3)/baz/(deeper:List(found,it,{0}))/biz?q={1}", complexStringEscapedPath, complexStringEscapedQuery);

            FinderRequestBuilder <Greeting, EmptyRecord> requestBuilder = new FinderRequestBuilder <Greeting, EmptyRecord>("foo/{one}/bar/{list}/baz/{complex}/biz");

            requestBuilder.Name(complexString);
            requestBuilder.SetPathKey("one", 1);
            requestBuilder.SetPathKey("list", new List <object>()
            {
                "foo", 2, 3
            });
            requestBuilder.SetPathKey("complex", new Dictionary <string, object>()
            {
                { "deeper", new List <object>()
                  {
                      "found", "it", complexString
                  } }
            });

            FinderRequest <Greeting, EmptyRecord> request = requestBuilder.Build();

            RequestUrlBuilder <CollectionResponse <Greeting, EmptyRecord> > urlBuilder = new RequestUrlBuilder <CollectionResponse <Greeting, EmptyRecord> >(request, "http://testprefix");
            Uri url = urlBuilder.Build();

            Assert.AreEqual(expected, url.AbsoluteUri);
        }
예제 #5
0
        public void Should_add_empty_query_values_if_requested_to()
        {
            var builder = new RequestUrlBuilder("http://foo");

            builder.AppendToQuery("key", string.Empty, true);

            builder.Build().Query.Should().Be("?key=");
        }
예제 #6
0
        public void Should_not_add_empty_query_values_by_default()
        {
            var builder = new RequestUrlBuilder("http://foo");

            builder.AppendToQuery("key", string.Empty);

            builder.Build().Query.Should().BeEmpty();
        }
        public void Should_produce_correct_uri_when_starting_from_non_empty_url_with_path()
        {
            var builder = new RequestUrlBuilder("initial/segments/")
            {
                "foo/", "bar/", "baz"
            };

            builder.Build().OriginalString.Should().Be("initial/segments/foo/bar/baz");
        }
        public void Should_produce_correct_uri_when_appending_path_segments_with_excess_slashes()
        {
            var builder = new RequestUrlBuilder
            {
                "11/", "/22/", "/33/", "/44"
            };

            builder.Build().OriginalString.Should().Be("11/22/33/44");
        }
        public void Should_produce_correct_uri_without_query_parameters()
        {
            var builder = new RequestUrlBuilder
            {
                "foo/", "bar/", "baz"
            };

            builder.Build().OriginalString.Should().Be("foo/bar/baz");
        }
        public void Should_produce_correct_uri_when_appending_path_segments_without_slashes()
        {
            var builder = new RequestUrlBuilder
            {
                "1", "2", "3", "4"
            };

            builder.Build().OriginalString.Should().Be("1/2/3/4");
        }
        public void Should_encode_query_parameter_names_and_values()
        {
            var builder = new RequestUrlBuilder
            {
                "foo/", "bar/", "baz",
                { "a?a", "b?b" },
            };

            builder.Build().OriginalString.Should().Be("foo/bar/baz?a%3Fa=b%3Fb");
        }
        public void Should_produce_correct_uri_when_starting_from_non_empty_url_with_path_and_query()
        {
            var builder = new RequestUrlBuilder("foo/bar/baz?a=1")
            {
                { "b", 2 },
                { "c", 3 }
            };

            builder.Build().OriginalString.Should().Be("foo/bar/baz?a=1&b=2&c=3");
        }
        public void Should_produce_correct_uri_with_query_parameters()
        {
            var builder = new RequestUrlBuilder
            {
                "foo/", "bar/", "baz",
                { "a", 1 },
                { "b", 2 }
            };

            builder.Build().OriginalString.Should().Be("foo/bar/baz?a=1&b=2");
        }
        private static Uri GetFullUri(string uriPath, Dictionary <string, object> uriQueryParams)
        {
            var urlBuilder = new RequestUrlBuilder(uriPath);

            if (uriQueryParams != null)
            {
                foreach (var queryParam in uriQueryParams)
                {
                    urlBuilder.AppendToQuery(queryParam.Key, queryParam.Value);
                }
            }
            return(urlBuilder.Build());
        }
        public void Should_not_be_usable_after_producing_an_url()
        {
            var builder = new RequestUrlBuilder
            {
                "foo/", "bar/", "baz"
            };

            builder.Build();

            Action pathAppend  = () => builder.AppendToPath("123");
            Action queryAppend = () => builder.AppendToQuery("123", "456");

            pathAppend.Should().Throw <ObjectDisposedException>().Which.ShouldBePrinted();
            queryAppend.Should().Throw <ObjectDisposedException>().Which.ShouldBePrinted();
        }
예제 #16
0
        public Uri GetUrl(string urlPrefix)
        {
            RequestUrlBuilder <TResponse> requestUrlBuilder = new RequestUrlBuilder <TResponse>(this, urlPrefix);

            return(requestUrlBuilder.Build());
        }