Exemple #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);
        }
Exemple #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);
        }
Exemple #3
0
        public void New_ShouldBuildBasicUriFromStringInput()
        {
            var result = FluentUriBuilder.New("http://thehost").Build();

            Assert.Equal("thehost", result.Host);
            Assert.Equal("http", result.Scheme);
        }
Exemple #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());
        }
Exemple #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());
        }
Exemple #6
0
        public void WithPath_ShouldAddPathToUriWithPath()
        {
            var result = FluentUriBuilder.New("http://host")
                         .WithPath("mypath/hello")
                         .Build();

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

            Assert.Equal("test", result.Scheme);
        }
Exemple #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);
        }
Exemple #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());
        }
Exemple #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());
        }
Exemple #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);
        }
Exemple #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());
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #15
0
 public void Host_CannotPassNullAsUriString()
 {
     try
     {
         FluentUriBuilder.New("http://test").WithHost(null);
     }
     catch (Exception e)
     {
         Assert.Equal("ContractException", e.GetType().Name);
     }
 }
Exemple #16
0
 public void WithFragment_ShouldThrowIfGivenEmptyString()
 {
     Assert.Throws <ArgumentException>(() => FluentUriBuilder.New("http://host:1234/test")
                                       .WithFragment(string.Empty));
 }
Exemple #17
0
 public void AddPathTemplate_ShouldThrowIfGivenEmptyString()
 {
     Assert.Throws <ArgumentException>(() => FluentUriBuilder.New("http://host:1234/test")
                                       .AddPathTemplate(string.Empty));
 }
Exemple #18
0
        public void New_ShouldProduceSameUriThatWasGiven(string uri)
        {
            var result = FluentUriBuilder.New(uri).Build();

            Assert.Equal(new Uri(uri), result);
        }
Exemple #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);
        }