Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //This name inverter Kata is a great way for a developer to practice their TDD skills
            //and hone their abilities to refactor their code with the safety net of the unit tests.
            //The code will take an input string and return a well formatted Name.
            //It will remove Honourifics as part of the business requirements if so detected [Mr. or Mrs.].
            //It will invert the first name as provided with the surname to give [Smith, John] to an input of [John Smith] and many other variations.
            //It will handle the correct removal of padding from the input string not only from the ends of the string but also in between word boundaries.

            var nameInverterUseCases = new List <(string NameToInvert, string ExpectedOutputOfTheNameInverter)>
            {
                ("", ""),
                ("", "       "),
                ("John", "John"),
                ("   John   ", "John"),
                ("John Smith", "Smith, John"),
                ("John      Smith", "Smith, John"),
                ("Mr. John Smith", "Smith, John"),
                ("Mrs. Sally Smith", "Smith, Sally"),
                ("John Smith Sr.", "Smith, John Sr."),
                ("John Smith Sr. PhD.", "Smith, John Sr. PhD."),
                ("Mr.    John Smith    Sr.     PhD.", "Smith, John Sr. PhD.")
            };

            foreach (var nameInverterUseCase in nameInverterUseCases)
            {
                Console.WriteLine($"The NameInverter is about to invert: {nameInverterUseCase.NameToInvert}");
                Console.WriteLine($"The expected output is: {NameInverter.Invert(nameInverterUseCase.NameToInvert)}");
            }

            Console.ReadLine();
        }
Ejemplo n.º 2
0
 public void Invert_null_shouldThrowNullReferenceException()
 {
     Assert.Throws <ArgumentNullException>(() => NameInverter.Invert(null));
 }
Ejemplo n.º 3
0
 public void Invert_FirstNameThenLastNameMultiplePostNominals_shouldReturnLastNameCommaFirstNamePostNominals()
 {
     Assert.Equal("Smith, John Sr. PhD.", NameInverter.Invert("John Smith Sr. PhD."));
 }
Ejemplo n.º 4
0
 public void Invert_FirstNameThenLastNameAcceptanceTest_shouldReturnLastNameCommaFirstNamePostNominals()
 {
     Assert.Equal("Smith, John Sr. PhD.", NameInverter.Invert("Mr.    John Smith    Sr.     PhD."));
 }
Ejemplo n.º 5
0
 public void Invert_honorificsMrsFirstNameThenLastName_shouldReturnLastNameCommaFirstName()
 {
     Assert.Equal("Smith, John", NameInverter.Invert("Mrs. John Smith"));
 }
Ejemplo n.º 6
0
 public void Invert_firstNameThenLastWithWhitespace_shouldReturnLastNameCommaFirstName()
 {
     Assert.Equal("Smith, John", NameInverter.Invert("John      Smith"));
 }
Ejemplo n.º 7
0
 public void Invert_firstNameWithWhitespace_shouldReturnFirstName()
 {
     Assert.Equal("John", NameInverter.Invert("   John   "));
 }
Ejemplo n.º 8
0
 public void Invert_manyEmptyWhitspaceCharacters_shouldReturnEmptyString()
 {
     Assert.Equal("", NameInverter.Invert("     "));
 }
Ejemplo n.º 9
0
 public void Invert_emptyString_shouldReturnEmptyString()
 {
     Assert.Equal("", NameInverter.Invert(""));
 }