/// <summary> /// The to title case. /// </summary> /// <param name="str"> /// The str. /// </param> /// <param name="tcase"> /// The tcase. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string ToTitleCase(this string str, TitleCase tcase) { if (string.IsNullOrEmpty(str)) { return(str); } str = str.ToLower(); switch (tcase) { case TitleCase.First: string[] strArray = str.Split(' '); if (strArray.Length > 1) { strArray[0] = ci.TextInfo.ToTitleCase(strArray[0]); return(string.Join(" ", strArray)); } break; case TitleCase.All: return(ci.TextInfo.ToTitleCase(str)); default: break; } return(ci.TextInfo.ToTitleCase(str)); }
public void NullOrEmptyValue_TitleCaseTest(string str) { //arrange var url = new URL(); //assert Assert.ThrowsException <ArgumentOutOfRangeException>(() => TitleCase.Exec(str)); }
public void Test002_GivenTitleCase_GetTitleCaseReturnsInputWithFirstLetterCapitalized() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("Apple", titleCase.GetTitleCase("apple")); // The issue wasn't that I needed to add this second assert, but that I skipped the 'refactor' step of 'Red, Green, Refactor' // to eliminate the magic character Assert.AreEqual("Knife", titleCase.GetTitleCase("knife")); }
public void NullSecondArg_TitleCaseTest() { //arrange var url = new URL(); string result = TitleCase.Exec("the quick brown fox"); //act string expected = "The Quick Brown Fox"; //assert Assert.IsTrue(result == expected); }
public void TestMult_TitleCaseTest() { //arrange var url = new URL(); string result = TitleCase.Exec("a clash of KINGS", "a an the of"); //act string expected = "A Clash of Kings"; //assert Assert.IsTrue(result == expected); }
public void Test004_GivenTitleCase_GetWordsFromStringMethodReturnsListOfCorrectStrings() { TitleCase titleCase = new TitleCase(); List <string> expectedResultList = new List <string>(); expectedResultList.Add("this"); expectedResultList.Add("is"); expectedResultList.Add("easy"); CollectionAssert.AreEqual(expectedResultList, titleCase.GetWordsFromString("this is easy")); }
public static string ToTitleCase(this string str, TitleCase tcase) { str = str.ToLower(); switch (tcase) { case TitleCase.Words: return(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(str.ToLower())); default: break; } return(str); }
public void RandomTest() { const int Tests = 100; for (int i = 0; i < Tests; ++i) { string test = String.Join(" ", String.Concat(new String('.', rnd.Next(40, 201)).Select(_ => chars[rnd.Next(0, chars.Length)])) .Split(' ').Where(s => !String.IsNullOrEmpty(s))).Trim(); string[] words = test.Split(' '); string minorWords = String.Join(" ", new string[] { words[rnd.Next(0, words.Length)], words[rnd.Next(0, words.Length)], words[rnd.Next(0, words.Length)], words[rnd.Next(0, words.Length)] }.Distinct()); string expected = TitleCaseTrue(test, minorWords); string actual = TitleCase.titleCase(test, minorWords); Assert.AreEqual(expected, actual); } }
public static string ToTitleCase(this string value, TitleCase titleCase = TitleCase.All) { CultureInfo cultureInfo = CultureInfo.CurrentCulture; value = value.ToLower(); switch (titleCase) { case TitleCase.First: var strArray = value.Split(' '); if (strArray.Length > 1) { strArray[0] = cultureInfo.TextInfo.ToTitleCase(strArray[0]); return(string.Join(" ", strArray)); } break; case TitleCase.All: default: return(cultureInfo.TextInfo.ToTitleCase(value)); } return(value); }
public void Test003_GivenTitleCase_GetTitleCaseReturnsInputWithFirstLetterLowerCaseDueToMinorWordsParameter() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("An apple", titleCase.GetTitleCase("an apple", "apple")); }
/// <summary> /// The to title case. /// </summary> /// <param name="str"> /// The str. /// </param> /// <param name="tcase"> /// The tcase. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string ToTitleCase(this string str, TitleCase tcase) { if (string.IsNullOrEmpty(str)) return str; str = str.ToLower(); switch (tcase) { case TitleCase.First: string[] strArray = str.Split(' '); if (strArray.Length > 1) { strArray[0] = ci.TextInfo.ToTitleCase(strArray[0]); return string.Join(" ", strArray); } break; case TitleCase.All: return ci.TextInfo.ToTitleCase(str); default: break; } return ci.TextInfo.ToTitleCase(str); }
public void Test012_GivenTitleCase_GetTitleCaseTreatsNullMinorWordsParameterAsBlankString() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("Abc Def Ghi", titleCase.GetTitleCase("aBC deF Ghi", null)); }
public void TestTitleCase(string sampleTitle, string sampleMinorWords, string expected) { Assert.Equal(expected, TitleCase.Title(sampleTitle, sampleMinorWords)); }
public void EmptyTitle() { Assert.Equal(string.Empty, TitleCase.Title(string.Empty)); }
public void Test010_GivenTitleCase_GetTitleCaseWorksEvenIfALaterWordIsTheSameAsTheFirstWord() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("The Wind in the Willows", titleCase.GetTitleCase("the wind in the willows", "the in")); }
public void Test009_GivenTitleCase_GetTitleCaseWorksEvenIfFirstLetterOfWordIsUsedLaterInWord() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("Wind in the Willows", titleCase.GetTitleCase("wind in the willows", "the in")); }
public void Test007_GivenTitleCase_GetTitleCaseReturnsWithFirstWordCapitalizedEvenThoughItIsPresentInMinorWords() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("A Clash of Jesters", titleCase.GetTitleCase("a clash of jesters", "of a")); }
public void Test005_GivenTitleCase_GetTitleCaseReturnsInputWithFirstLettersOfTwoWordsCapitalized() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("Apple Pie", titleCase.GetTitleCase("apple pie")); }
public void QuickBrownFoxTest() { Assert.Equal("The Quick Brown Fox", TitleCase.Title("the quick brown fox")); }
public void Test006_GivenTitleCase_GetTitleCaseReturnsInputWithFirstAndFourthWordsTitleCasedSecondAndThirdWordsLowerCase() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("Gone with the Wind", titleCase.GetTitleCase("gone with the wind", "the with")); }
public void MyTest(string sampleTitle, string sampleMinorWords, string expected) { Assert.AreEqual(expected, TitleCase.titleCase(sampleTitle, sampleMinorWords)); }
public void Test008_GivenTitleCase_GetTitleCaseMakesLowerCaseAllLettersAfterTheFirstInEachWord() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("Wind in the Hills", titleCase.GetTitleCase("WIND IN THE HILLS", "The In")); }
public void MyTest2() { Assert.AreEqual("", TitleCase.titleCase("")); }
public void Test001_GivenTitleCase_GetTitleCaseReturnsInputString() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("Apple", titleCase.GetTitleCase("Apple")); }
public void MyTest3() { Assert.AreEqual("The Quick Brown Fox", TitleCase.titleCase("the quick brown fox")); }
public void Test011_GivenTitleCase_GetTitleCaseReturnsCapitalisedFirstWordEvenWhenInputAndMinorWordsAreTheSameAndLowerCase() { TitleCase titleCase = new TitleCase(); Assert.AreEqual("Ab", titleCase.GetTitleCase("ab", "ab")); }
public string GetTitleCase_Test(string minor, string original) { return(TitleCase.GetTitleCase(minor, original)); }