Add support for WithoutDefaultPort as WithPort doesn't allow "-1" to be sent to hide DefaultPorts
This commit is contained in:
@@ -78,6 +78,22 @@ namespace FluentUriBuilder.Tests
|
||||
Assert.Equal(url.Port, 22);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithoutDefaultPort()
|
||||
{
|
||||
var url = new UriBuilder("http://awesome.com:80")
|
||||
.WithoutDefaultPort();
|
||||
Assert.Equal("http://awesome.com", url.Uri.ToString());
|
||||
|
||||
url = new UriBuilder("http://awesome.com:443")
|
||||
.WithoutDefaultPort();
|
||||
Assert.Equal("http://awesome.com:443", url.Uri.ToString());
|
||||
|
||||
url = new UriBuilder("https://awesome.com:443")
|
||||
.WithoutDefaultPort();
|
||||
Assert.Equal("https://awesome.com", url.Uri.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithHttps()
|
||||
{
|
||||
|
||||
@@ -81,6 +81,17 @@ namespace System
|
||||
return bld;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the port number for default ports
|
||||
/// </summary>
|
||||
/// <param name="bld"></param>
|
||||
/// <returns></returns>
|
||||
public static UriBuilder WithoutDefaultPort(this UriBuilder bld)
|
||||
{
|
||||
if (bld.Uri.IsDefaultPort) bld.Port = -1;
|
||||
return bld;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// appends a path segment to the path. Can be called multiple times to append multiple segments
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user