From 5275aa72fb893d197d2b02d0e2b8efa6b074db8b Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 10 Jun 2019 21:32:09 -0700 Subject: [PATCH] Clean up FirstCharacterToLower extension + tests --- ...rFixture.cs => FirstCharacterToLowerFixture.cs} | 4 +++- .../FirstCharcacterToUpperFixture.cs | 2 ++ .../NzbDrone.Common.Test.csproj | 2 +- src/NzbDrone.Common/Extensions/StringExtensions.cs | 14 ++++++++++++-- 4 files changed, 18 insertions(+), 4 deletions(-) rename src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/{FirstCharcacterToLowerFixture.cs => FirstCharacterToLowerFixture.cs} (82%) diff --git a/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToLowerFixture.cs b/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharacterToLowerFixture.cs similarity index 82% rename from src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToLowerFixture.cs rename to src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharacterToLowerFixture.cs index e1314dcca..901668734 100644 --- a/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToLowerFixture.cs +++ b/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharacterToLowerFixture.cs @@ -5,11 +5,13 @@ using NzbDrone.Common.Extensions; 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); diff --git a/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToUpperFixture.cs b/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToUpperFixture.cs index bf8169b60..53e221f4e 100644 --- a/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToUpperFixture.cs +++ b/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToUpperFixture.cs @@ -10,6 +10,8 @@ namespace NzbDrone.Common.Test.ExtensionTests.StringExtensionTests [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); diff --git a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index 9f547171e..7d28931b1 100644 --- a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -85,7 +85,7 @@ - + diff --git a/src/NzbDrone.Common/Extensions/StringExtensions.cs b/src/NzbDrone.Common/Extensions/StringExtensions.cs index 3de53ef0d..b7d058657 100644 --- a/src/NzbDrone.Common/Extensions/StringExtensions.cs +++ b/src/NzbDrone.Common/Extensions/StringExtensions.cs @@ -24,12 +24,22 @@ namespace NzbDrone.Common.Extensions 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)