diff --git a/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharacterToLowerFixture.cs b/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharacterToLowerFixture.cs new file mode 100644 index 000000000..d2df657d4 --- /dev/null +++ b/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharacterToLowerFixture.cs @@ -0,0 +1,36 @@ +using System.Globalization; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.Extensions; + +namespace NzbDrone.Common.Test.ExtensionTests.StringExtensionTests +{ + [TestFixture] + 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); + } + + [Test] + public void should_lower_case_first_character_regardless_of_culture() + { + var current = CultureInfo.CurrentCulture; + CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("tr-TR"); + try + { + "InfInite".FirstCharToLower().Should().Be("infInite"); + } + finally + { + CultureInfo.CurrentCulture = current; + } + } + } +} diff --git a/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToUpperFixture.cs b/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToUpperFixture.cs new file mode 100644 index 000000000..53e221f4e --- /dev/null +++ b/src/NzbDrone.Common.Test/ExtensionTests/StringExtensionTests/FirstCharcacterToUpperFixture.cs @@ -0,0 +1,20 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.Extensions; + +namespace NzbDrone.Common.Test.ExtensionTests.StringExtensionTests +{ + [TestFixture] + 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); + } + } +} diff --git a/src/NzbDrone.Common.Test/ExtensionTests/UrlExtensionsFixture.cs b/src/NzbDrone.Common.Test/ExtensionTests/UrlExtensionsFixture.cs new file mode 100644 index 000000000..eae0736dc --- /dev/null +++ b/src/NzbDrone.Common.Test/ExtensionTests/UrlExtensionsFixture.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.Extensions; + +namespace NzbDrone.Common.Test.ExtensionTests +{ + [TestFixture] + public class UrlExtensionsFixture + { + [TestCase("http://my.local/url")] + [TestCase("https://my.local/url")] + public void should_report_as_valid_url(string url) + { + url.IsValidUrl().Should().BeTrue(); + } + + [TestCase("")] + [TestCase(" http://my.local/url")] + [TestCase("http://my.local/url ")] + public void should_report_as_invalid_url(string url) + { + url.IsValidUrl().Should().BeFalse(); + } + } +} diff --git a/src/NzbDrone.Common.Test/HashUtilFixture.cs b/src/NzbDrone.Common.Test/HashUtilFixture.cs new file mode 100644 index 000000000..02869fa24 --- /dev/null +++ b/src/NzbDrone.Common.Test/HashUtilFixture.cs @@ -0,0 +1,21 @@ +using FluentAssertions; +using NUnit.Framework; + +namespace NzbDrone.Common.Test +{ + [TestFixture] + public class HashUtilFixture + { + [Test] + public void should_create_anon_id() + { + HashUtil.AnonymousToken().Should().NotBeNullOrEmpty(); + } + + [Test] + public void should_create_the_same_id() + { + HashUtil.AnonymousToken().Should().Be(HashUtil.AnonymousToken()); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index 067706a2f..250da36ed 100644 --- a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -89,6 +89,10 @@ + + + + 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 @@ 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)