Merge pull request #15 from adriangodong/fixed-bad-fragment-char

Fixed bad fragment char
This commit is contained in:
Tommy Parnell
2017-10-20 02:06:47 -04:00
committed by GitHub
2 changed files with 43 additions and 1 deletions

View File

@@ -71,6 +71,14 @@ namespace FluentUriBuilder.Tests
Assert.Equal("http://awesome.com/?awesome", url.Uri.ToString()); Assert.Equal("http://awesome.com/?awesome", url.Uri.ToString());
} }
[Fact]
public void TestAddFragmentArray()
{
var url = new UriBuilder("http://awesome.com")
.WithFragment("awesome", "cool", "dawg");
Assert.Equal("http://awesome.com/#awesome=cool,dawg", url.Uri.ToString());
}
[Fact] [Fact]
public void TestAddFragmentArrayint() public void TestAddFragmentArrayint()
{ {
@@ -174,6 +182,40 @@ namespace FluentUriBuilder.Tests
Assert.Equal("http://awesome.com/?yo=dawg&troll=toll&hammer", url.Uri.ToString()); Assert.Equal("http://awesome.com/?yo=dawg&troll=toll&hammer", url.Uri.ToString());
} }
[Fact]
public void AddFragmentWithNoValue()
{
var url = new UriBuilder("http://awesome.com")
.WithFragment("awesome", "yodawg")
.WithFragment("fun", null)
.WithFragment("cool", string.Empty);
Assert.Equal("http://awesome.com/#awesome=yodawg&fun&cool", url.Uri.ToString());
}
[Fact]
public void TestAddTwoUrlFragments()
{
var url = new UriBuilder("http://awesome.com")
.WithFragment("awesome", "yodawg")
.WithFragment("supg", "no2")
.WithFragment("supgf", "no22");
Assert.Equal("http://awesome.com/#awesome=yodawg&supg=no2&supgf=no22", url.Uri.ToString());
}
[Fact]
public void AddDictOfFragments()
{
var dictionary = new Dictionary<string, string>()
{
["yo"] = "dawg",
["troll"] = "toll",
["hammer"] = string.Empty
};
var url = new UriBuilder("http://awesome.com")
.WithFragment(dictionary);
Assert.Equal("http://awesome.com/#yo=dawg&troll=toll&hammer", url.Uri.ToString());
}
[Fact] [Fact]
public void TestToEscapedString() public void TestToEscapedString()
{ {

View File

@@ -99,7 +99,7 @@ namespace System
{ {
valuesEnum = new string[0]; valuesEnum = new string[0];
} }
var intitialValue = string.IsNullOrWhiteSpace(bld.Fragment) ? "" : $"{bld.Fragment.TrimStart('?')}&"; var intitialValue = string.IsNullOrWhiteSpace(bld.Fragment) ? "" : $"{bld.Fragment.TrimStart('#')}&";
bld.Fragment = intitialValue.AppendKeyValue(key, valuesEnum); bld.Fragment = intitialValue.AppendKeyValue(key, valuesEnum);
return bld; return bld;
} }