1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00

Clean up FirstCharacterToLower extension + tests

This commit is contained in:
Mark McDowall 2019-06-10 21:32:09 -07:00
parent 9e45b9e808
commit 5275aa72fb
4 changed files with 18 additions and 4 deletions

View File

@ -5,11 +5,13 @@
namespace NzbDrone.Common.Test.ExtensionTests.StringExtensionTests
{
[TestFixture]
public class FirstCharcacterToLowerFixture
public class FirstCharacterToLowerFixture
{
[TestCase("Hello", "hello")]
[TestCase("CamelCase", "camelCase")]
[TestCase("A Full Sentence", "a Full Sentence")]
[TestCase("", "")]
[TestCase(null, "")]
public void should_lower_case_first_character(string input, string expected)
{
input.FirstCharToLower().Should().Be(expected);

View File

@ -10,6 +10,8 @@ public class FirstCharcacterToUpperFixture
[TestCase("hello", "Hello")]
[TestCase("camelCase", "CamelCase")]
[TestCase("a full sentence", "A full sentence")]
[TestCase("", "")]
[TestCase(null, "")]
public void should_capitalize_first_character(string input, string expected)
{
input.FirstCharToUpper().Should().Be(expected);

View File

@ -85,7 +85,7 @@
<Compile Include="ExtensionTests\IEnumerableExtensionTests\IntersectByFixture.cs" />
<Compile Include="ExtensionTests\Int64ExtensionFixture.cs" />
<Compile Include="ExtensionTests\IPAddressExtensionsFixture.cs" />
<Compile Include="ExtensionTests\StringExtensionTests\FirstCharcacterToLowerFixture.cs" />
<Compile Include="ExtensionTests\StringExtensionTests\FirstCharacterToLowerFixture.cs" />
<Compile Include="ExtensionTests\StringExtensionTests\FirstCharcacterToUpperFixture.cs" />
<Compile Include="ExtensionTests\UrlExtensionsFixture.cs" />
<Compile Include="HashUtilFixture.cs" />

View File

@ -24,12 +24,22 @@ public static object NullSafe(this object target)
public static string FirstCharToLower(this string input)
{
return input.First().ToString().ToLower() + input.Substring(1);
if (string.IsNullOrEmpty(input))
{
return string.Empty;
}
return char.ToLowerInvariant(input.First()) + input.Substring(1);
}
public static string FirstCharToUpper(this string input)
{
return input.First().ToString().ToUpper() + input.Substring(1);
if (string.IsNullOrEmpty(input))
{
return string.Empty;
}
return char.ToUpperInvariant(input.First()) + input.Substring(1);
}
public static string Inject(this string format, params object[] formattingArgs)