Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Text.RegularExpressions;
using System.Globalization;

namespace App
{
Expand All @@ -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();
}
}
}
}
12 changes: 12 additions & 0 deletions AppTest/Program.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exception>(action);
}
[Fact]
public void ConvertToTitleCase_Simple()
{
Expand Down