コード例 #1
0
        public void WithFragment_ShouldSetPreExistingFragment()
        {
            var result = FluentUriBuilder.New("http://host:1234/test#frag")
                         .Build().ToString();

            Assert.Equal("http://host:1234/test#frag", result);
        }
コード例 #2
0
        public void WithHost_ShouldUpdateHost()
        {
            var result = FluentUriBuilder.New("http://host:1234/test")
                         .WithHost("newhost").Build();

            Assert.Equal(new Uri("http://newhost:1234/test"), result);
        }
コード例 #3
0
        public void New_ShouldBuildBasicUriFromStringInput()
        {
            var result = FluentUriBuilder.New("http://thehost").Build();

            Assert.Equal("thehost", result.Host);
            Assert.Equal("http", result.Scheme);
        }
コード例 #4
0
        public void New_ShouldBuildUriFromStringInputWithPath()
        {
            var result = FluentUriBuilder.New("http://thehost/thepath").Build();

            Assert.Equal("thehost", result.Host);
            Assert.Equal("http", result.Scheme);
            Assert.Equal("http://thehost/thepath", result.ToString());
        }
コード例 #5
0
        public void New_ShouldBuildUriFromStringInputWithPathAndPortAndQueryString()
        {
            var result = FluentUriBuilder.New("http://thehost:8945/thepath?id=54").Build();

            Assert.Equal("thehost", result.Host);
            Assert.Equal("http", result.Scheme);
            Assert.Equal("http://thehost:8945/thepath?id=54", result.ToString());
        }
コード例 #6
0
        public void WithPath_ShouldAddPathToUriWithPath()
        {
            var result = FluentUriBuilder.New("http://host")
                         .WithPath("mypath/hello")
                         .Build();

            Assert.Equal("/mypath/hello", result.AbsolutePath);
        }
コード例 #7
0
        public void WithScheme_ShouldChangeScheme()
        {
            var result = FluentUriBuilder.New("http://host")
                         .WithScheme("test")
                         .Build();

            Assert.Equal("test", result.Scheme);
        }
コード例 #8
0
        public void AddQuery_ShouldAddQueryParameter()
        {
            var result = FluentUriBuilder.New("http://host:1234/test")
                         .AddQuery("myparam", "myvalue")
                         .Build().ToString();

            Assert.Equal("http://host:1234/test?myparam=myvalue", result);
        }
コード例 #9
0
        public void WithPathSegment_ShouldSetSegmentForTemplate()
        {
            var result = FluentUriBuilder.New("http://host:1234/{seg1}")
                         .WithSegment("seg1", "segmentone")
                         .Build();

            Assert.Equal("http://host:1234/segmentone", result.ToString());
        }
コード例 #10
0
        public void WithPort_ShouldSetPort()
        {
            var result = FluentUriBuilder.New("http://host/path")
                         .WithPort(1234)
                         .Build();

            Assert.Equal(1234, result.Port);
            Assert.Equal("http://host:1234/path", result.ToString());
        }
コード例 #11
0
        public void AddPathTemplate_ShouldHandleSlashesCorrectlyWhenTemplateBeginsWithSlash()
        {
            var result = FluentUriBuilder.New("http://host:1234/test")
                         .AddPathTemplate("/{test}/whatever/{test2}")
                         .WithSegment("test", "karl")
                         .WithSegment("test2", "karl2")
                         .Build();

            Assert.Equal(new Uri("http://host:1234/test/karl/whatever/karl2"), result);
        }
コード例 #12
0
        public void WithPathTemplate_ShouldAddTemplateToPath()
        {
            var result = FluentUriBuilder.New("http://host:1234/{seg1}")
                         .WithSegment("seg1", "segone")
                         .AddPathTemplate("{newseg}/someseg")
                         .WithSegment("newseg", "test")
                         .Build();

            Assert.Equal("http://host:1234/segone/test/someseg", result.ToString());
        }
コード例 #13
0
        public void Explore()
        {
            var result = FluentUriBuilder.New("http://host:1234/test")
                         .AddPathTemplate("/{test}/whatever/{test2}")
                         .WithSegment("test", "karl")
                         .WithSegment("test2", "karl2")
                         .Build();

            Assert.Equal(new Uri("http://host:1234/test/karl/whatever/karl2"), result);
        }
コード例 #14
0
        public void WithQueries_ShouldAddMultipleQueryParamerters2()
        {
            var result = FluentUriBuilder.New("http://host:1234/test")
                         .AddQueries(new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("what", "hey"), new KeyValuePair <string, string>("no", "yes")
            })
                         .Build();

            Assert.Equal(new Uri("http://host:1234/test?what=hey&no=yes"), result);
        }
コード例 #15
0
 public void Host_CannotPassNullAsUriString()
 {
     try
     {
         FluentUriBuilder.New("http://test").WithHost(null);
     }
     catch (Exception e)
     {
         Assert.Equal("ContractException", e.GetType().Name);
     }
 }
コード例 #16
0
 public void WithFragment_ShouldThrowIfGivenEmptyString()
 {
     Assert.Throws <ArgumentException>(() => FluentUriBuilder.New("http://host:1234/test")
                                       .WithFragment(string.Empty));
 }
コード例 #17
0
 public void AddPathTemplate_ShouldThrowIfGivenEmptyString()
 {
     Assert.Throws <ArgumentException>(() => FluentUriBuilder.New("http://host:1234/test")
                                       .AddPathTemplate(string.Empty));
 }
コード例 #18
0
        public void New_ShouldProduceSameUriThatWasGiven(string uri)
        {
            var result = FluentUriBuilder.New(uri).Build();

            Assert.Equal(new Uri(uri), result);
        }
コード例 #19
0
        public void WithQueries_ShouldAddMultipleQueryParamerters()
        {
            var result = FluentUriBuilder.New("http://host:1234/test").AddQueries(new[] { "what=hey", "no=yes" }).Build();

            Assert.Equal(new Uri("http://host:1234/test?what=hey&no=yes"), result);
        }