-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e60d64e
commit a7be86b
Showing
5 changed files
with
59 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using IIIFAuth2.API.Utils; | ||
|
||
namespace IIIFAuth2.API.Tests.Utils; | ||
|
||
public class StringX | ||
{ | ||
[Fact] | ||
public void EnsureEndsWith_ReturnsProvidedValue_IfAlreadyEndsWith() | ||
{ | ||
// Arrange | ||
const string val = "vultureprince"; | ||
|
||
// Act | ||
var actual = val.EnsureEndsWith("ce"); | ||
|
||
// Assert | ||
actual.Should().Be(val); | ||
} | ||
|
||
[Fact] | ||
public void EnsureEndsWith_AppendsValue_IfAlreadyEndsWith() | ||
{ | ||
// Arrange | ||
const string val = "vultureprince"; | ||
const string expected = "vultureprince/"; | ||
|
||
// Act | ||
var actual = val.EnsureEndsWith("/"); | ||
|
||
// Assert | ||
actual.Should().Be(expected); | ||
} | ||
} |
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
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,13 @@ | ||
namespace IIIFAuth2.API.Utils; | ||
|
||
public static class StringX | ||
{ | ||
/// <summary> | ||
/// Ensure that strings ends with provided value, adding it if not. | ||
/// </summary> | ||
/// <param name="str">String to check</param> | ||
/// <param name="endsWith">Value to ensure string ends with</param> | ||
/// <returns>Provided string if it already ends with value, or provided string with value appended</returns> | ||
public static string EnsureEndsWith(this string str, string endsWith) | ||
=> str.EndsWith(endsWith) ? str : $"{str}{endsWith}"; | ||
} |