diff --git a/App/Program.cs b/App/Program.cs index c4c26a8..9d42245 100644 --- a/App/Program.cs +++ b/App/Program.cs @@ -1,4 +1,6 @@ using System; +using System.Text.RegularExpressions; +using System.Globalization; namespace App { @@ -11,12 +13,39 @@ static void Main(string[] args) public static string ConvertToTitleCase(string inpStr) { - return inpStr; + + if (String.IsNullOrEmpty(inpStr)) + { + throw new Exception(); + } + // remove non alphaNum chars + Regex regex = new Regex("[^a-zA-Z0-9]"); + String outStr = regex.Replace(inpStr, " "); + + //trim pre/post whitespace char + char[] trimChars = { '*', ' ', '\'' }; + outStr = outStr.Trim(trimChars); + + // convert case to title + TextInfo locTI = new CultureInfo("en-US", false).TextInfo; + outStr = locTI.ToLower(outStr); + outStr = locTI.ToTitleCase(outStr); + + return outStr; } public static string ConvertUnixToDateString(long? inpUnixSeconds) { - return inpUnixSeconds.ToString(); + if (inpUnixSeconds.HasValue)// test for null + { + DateTimeOffset outDate = DateTimeOffset.FromUnixTimeSeconds(inpUnixSeconds.Value); + string outDateStr = outDate.ToString("MMMM d, yyyy"); + return outDateStr;//inpUnixSeconds.ToString(); + } + else + { + throw new Exception(); + } } } } \ No newline at end of file diff --git a/AppTest/Program.Tests.cs b/AppTest/Program.Tests.cs index f948724..6899e8f 100644 --- a/AppTest/Program.Tests.cs +++ b/AppTest/Program.Tests.cs @@ -6,6 +6,18 @@ namespace AppTest { public class ProgramTests { + [Fact] + public void ConvertToTitleCase_Null() + { + // Given + String testStr = null; + + // When + Action action = () => Program.ConvertToTitleCase(testStr); + + // Then + Assert.Throws(action); + } [Fact] public void ConvertToTitleCase_Simple() {