Advertisement
Caminhoneiro

String Converter example and Unit Test

Jul 16th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. //Extension method    
  2.  
  3. public static class StringExtensions
  4.     {
  5.         /// <summary>
  6.         /// Converts a list of strings to title case
  7.         /// </summary>
  8.         public static string ConvertToTitleCase(this string source)
  9.         {
  10.             CultureInfo cultureInfo   = Thread.CurrentThread.CurrentCulture;
  11.             TextInfo textInfo = cultureInfo.TextInfo;
  12.  
  13.             return textInfo.ToTitleCase(source);
  14.         }
  15.     }
  16.  
  17.  
  18.  
  19. //Unit Test
  20.     [TestClass]
  21.     public class StringExtensionsTest
  22.     {
  23.         public TestContext TestContext { get; set; }
  24.  
  25.         [TestMethod]
  26.         public void ConvertToTitleCase()
  27.         {
  28.             // Arrange
  29.             var source = "the return of the king";
  30.             var expected = "The Return Of The King";
  31.  
  32.             // Act
  33.            //var result = StringExtensions.ConvertToTitleCase(source);
  34.             var result = source.ConvertToTitleCase();
  35.  
  36.             // Assert
  37.             Assert.IsNotNull(result);
  38.             Assert.AreEqual(expected, result);
  39.         }
  40.  
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement