-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduced UriBuilder.AppendPath extension to be used instead of UriBuilder.Path * Updated version
- Loading branch information
Huib Piguillet
authored
Oct 20, 2021
1 parent
d2a3e61
commit 7810cb0
Showing
5 changed files
with
56 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
|
||
namespace Bynder.Sdk.Extensions | ||
{ | ||
public static class UriBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Allows to append a path to a url without overriding the existing path | ||
/// (which happens when you would set the Path property). | ||
/// | ||
/// For example, UriBuilder("https://example.com/base") { Path = "path/to/something" } | ||
/// will result in "https://example.com/path/to/something" (removing the "base" part) | ||
/// | ||
/// While UriBuilder("https://example.com/base").AppendPath("path/to/something") | ||
/// will result in "https://example.com/base/path/to/something" | ||
/// | ||
/// It will automatically ensure that the paths are combined correctly using only one "/". | ||
/// </summary> | ||
/// <param name="uriBuilder">extended UriBuilder instance</param> | ||
/// <param name="path">path to be appended to the full url</param> | ||
/// <returns>UriBuilder instance with the appended path</returns> | ||
public static UriBuilder AppendPath(this UriBuilder uriBuilder, String path) | ||
{ | ||
uriBuilder.Path = $"{uriBuilder.Path.TrimEnd('/')}/{path.TrimStart('/')}"; | ||
return uriBuilder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using Bynder.Sdk.Extensions; | ||
using Xunit; | ||
|
||
namespace Bynder.Test.Extensions | ||
{ | ||
public class UriBuilderExtensionsTest | ||
{ | ||
[Fact] | ||
public void PathsAreCorrectlyAppended() | ||
{ | ||
var expectedUrl = "https://example.com:443/base/path/to/something"; | ||
Assert.Equal(expectedUrl, new UriBuilder("https://example.com/base").AppendPath("path/to/something").ToString()); | ||
Assert.Equal(expectedUrl, new UriBuilder("https://example.com/base").AppendPath("/path/to/something").ToString()); | ||
Assert.Equal(expectedUrl, new UriBuilder("https://example.com/base/").AppendPath("path/to/something").ToString()); | ||
Assert.Equal(expectedUrl, new UriBuilder("https://example.com/base/").AppendPath("/path/to/something").ToString()); | ||
} | ||
} | ||
|
||
} |