Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
        public void NullOrEmptyValue_TitleCaseTest(string str)
        {
            //arrange
            var url = new URL();

            //assert
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => TitleCase.Exec(str));
        }
Esempio n. 3
0
        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"));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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"));
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
		}
Esempio n. 12
0
        public void Test012_GivenTitleCase_GetTitleCaseTreatsNullMinorWordsParameterAsBlankString()
        {
            TitleCase titleCase = new TitleCase();

            Assert.AreEqual("Abc Def Ghi", titleCase.GetTitleCase("aBC deF Ghi", null));
        }
Esempio n. 13
0
 public void TestTitleCase(string sampleTitle, string sampleMinorWords, string expected)
 {
     Assert.Equal(expected, TitleCase.Title(sampleTitle, sampleMinorWords));
 }
Esempio n. 14
0
 public void EmptyTitle()
 {
     Assert.Equal(string.Empty, TitleCase.Title(string.Empty));
 }
Esempio n. 15
0
        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"));
        }
Esempio n. 16
0
        public void Test009_GivenTitleCase_GetTitleCaseWorksEvenIfFirstLetterOfWordIsUsedLaterInWord()
        {
            TitleCase titleCase = new TitleCase();

            Assert.AreEqual("Wind in the Willows", titleCase.GetTitleCase("wind in the willows", "the in"));
        }
Esempio n. 17
0
        public void Test007_GivenTitleCase_GetTitleCaseReturnsWithFirstWordCapitalizedEvenThoughItIsPresentInMinorWords()
        {
            TitleCase titleCase = new TitleCase();

            Assert.AreEqual("A Clash of Jesters", titleCase.GetTitleCase("a clash of jesters", "of a"));
        }
Esempio n. 18
0
        public void Test005_GivenTitleCase_GetTitleCaseReturnsInputWithFirstLettersOfTwoWordsCapitalized()
        {
            TitleCase titleCase = new TitleCase();

            Assert.AreEqual("Apple Pie", titleCase.GetTitleCase("apple pie"));
        }
Esempio n. 19
0
 public void QuickBrownFoxTest()
 {
     Assert.Equal("The Quick Brown Fox", TitleCase.Title("the quick brown fox"));
 }
Esempio n. 20
0
        public void Test006_GivenTitleCase_GetTitleCaseReturnsInputWithFirstAndFourthWordsTitleCasedSecondAndThirdWordsLowerCase()
        {
            TitleCase titleCase = new TitleCase();

            Assert.AreEqual("Gone with the Wind", titleCase.GetTitleCase("gone with the wind", "the with"));
        }
Esempio n. 21
0
 public void MyTest(string sampleTitle, string sampleMinorWords, string expected)
 {
     Assert.AreEqual(expected, TitleCase.titleCase(sampleTitle, sampleMinorWords));
 }
Esempio n. 22
0
        public void Test008_GivenTitleCase_GetTitleCaseMakesLowerCaseAllLettersAfterTheFirstInEachWord()
        {
            TitleCase titleCase = new TitleCase();

            Assert.AreEqual("Wind in the Hills", titleCase.GetTitleCase("WIND IN THE HILLS", "The In"));
        }
Esempio n. 23
0
 public void MyTest2()
 {
     Assert.AreEqual("", TitleCase.titleCase(""));
 }
Esempio n. 24
0
        public void Test001_GivenTitleCase_GetTitleCaseReturnsInputString()
        {
            TitleCase titleCase = new TitleCase();

            Assert.AreEqual("Apple", titleCase.GetTitleCase("Apple"));
        }
Esempio n. 25
0
 public void MyTest3()
 {
     Assert.AreEqual("The Quick Brown Fox", TitleCase.titleCase("the quick brown fox"));
 }
Esempio n. 26
0
        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));
 }