public void Parse_MrJonADOTWaalJr() { var fullName = "Mr. Jon A. Waal Jr."; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Jon", target.FirstName); Assert.Equal("Waal", target.LastName); Assert.Equal("A", target.MiddleName); Assert.Equal("Mr.", target.Title); Assert.Equal("Jr.", target.Suffix); }
public void Parse_PasqualeQuotePatQuoteJohnson() { var fullName = "Pasquale 'Pat' Johnson"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Pasquale", target.FirstName); Assert.Equal("Johnson", target.LastName); Assert.Equal("Pasquale Johnson", target.DisplayName); Assert.Equal("Pat", target.NickName); }
public void Parse_ManuelSpaceEsquipulasSpaceSohom() { var fullName = "Manuel Esquipulas Sohom"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Manuel", target.FirstName); Assert.Equal("Esquipulas", target.MiddleName); Assert.Equal("Sohom", target.LastName); Assert.Equal("Manuel Esquipulas Sohom", target.DisplayName); }
public void Parse_JoseMiguelDelaVega() { var fullName = "Jose Miguel de la Vega"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Jose", target.FirstName); Assert.Equal("Miguel", target.MiddleName); Assert.Equal("de la Vega", target.LastName); Assert.Equal(fullName, target.DisplayName); }
public void Parse_TammySpaceLDotVanSpaceBaker() { var fullName = "Tammy L. van Baker"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Tammy", target.FirstName); Assert.Equal("L.", target.MiddleName); Assert.Equal("van Baker", target.LastName); Assert.Equal("Tammy L. van Baker", target.DisplayName); }
public void Parse_MrJackJohnsonEsq() { var fullName = @"Mr.Jack Johnson, ESQ"""; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Mr.", target.Title); Assert.Equal("Jack", target.FirstName); Assert.Equal("Johnson", target.LastName); Assert.Equal(@"ESQ""", target.Suffix); Assert.Equal("Jack Johnson", target.DisplayName); }
public void Parse_BernieSanders() { var fullName = "Sen. Bernard “Bernie” Sanders"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Bernard", target.FirstName); Assert.Equal("Sanders", target.LastName); Assert.Equal("Bernard Sanders", target.DisplayName); Assert.Equal("Sen.", target.Title); Assert.Equal("Bernie", target.NickName); }
public void Parse_QuincyDeLaRosaSr() { var fullName = "Quincy De La Rosa Sr"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Quincy", target.FirstName); Assert.Equal("De La Rosa", target.LastName); Assert.Equal("Sr", target.Suffix); Assert.Equal("Quincy De La Rosa", target.DisplayName); }
public void Parse_Space() { var fullName = " "; var target = new FullNameParser(fullName); target.Parse(); Assert.Null(target.Title); Assert.Null(target.FirstName); Assert.Null(target.MiddleName); Assert.Null(target.LastName); Assert.Null(target.Suffix); }
public void Parse_CDOTJDOTSpaceFosterIII() { var fullName = "C.J. Foster III"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("C.", target.FirstName); Assert.Equal("J.", target.MiddleName); Assert.Equal("Foster", target.LastName); Assert.Equal("III", target.Suffix); Assert.Equal("C. J. Foster", target.DisplayName); }
public void Parse_MrJackFrancisMarionVanDerWaalSr() { var fullName = "Mr. Jack Francis Marion Van Der Waal Sr."; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Mr.", target.Title); Assert.Equal("Jack", target.FirstName); Assert.Equal("Francis Marion", target.MiddleName); Assert.Equal("Van Der Waal", target.LastName); Assert.Equal("Sr.", target.Suffix); }
public void Parse_MrDOTPasqualeSCOPEPatSCOPEJohnson() { var fullName = "Mr. Pasquale (Pat) Johnson"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Mr.", target.Title); Assert.Equal("Pasquale", target.FirstName); Assert.Equal("Johnson", target.LastName); Assert.Equal("Pasquale Johnson", target.DisplayName); Assert.Equal("Pat", target.NickName); }
public void Parse_AffiliatedForkliftServices() { var fullName = "AFFILIATED FORKLIFT SERVICES"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("AFFILIATED FORKLIFT SERVICES", target.DisplayName); Assert.Null(target.FirstName); Assert.Null(target.LastName); Assert.Null(target.Title); Assert.Null(target.NickName); }
public void Parse_MariaSpaceDeloresSpaceEsquivelDashMoreno() { var fullName = "Maria Delores Esquivel-Moreno"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Maria", target.FirstName); Assert.Equal("Delores", target.MiddleName); Assert.Equal("Esquivel-Moreno", target.LastName); Assert.Equal(fullName, target.DisplayName); }
public void Parse_PhilipDeHartEsq() { var fullName = "Philip DeHart ESQ"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Philip", target.FirstName); Assert.Equal("DeHart", target.LastName); Assert.Equal("ESQ", target.Suffix); Assert.Equal("Philip DeHart", target.DisplayName); Assert.Null(target.Title); }
public void Parse_TammySpaceLDotBlytheHyphenBakerSpaceII() { var fullName = "Tammy L. Blythe-Baker II"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Tammy", target.FirstName); Assert.Equal("L", target.MiddleName); Assert.Equal("Blythe-Baker", target.LastName); Assert.Equal("II", target.Suffix); Assert.Equal("Tammy L Blythe-Baker", target.DisplayName); }
public void Parse_EsquivelDashMorenoCommaMariaSpaceDeloresSpaceThird() { var fullName = "Esquivel-Moreno, Maria Delores III"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Maria", target.FirstName); Assert.Equal("Delores", target.MiddleName); Assert.Equal("III", target.Suffix); Assert.Equal("Esquivel-Moreno", target.LastName); Assert.Equal("Maria Esquivel-Moreno", target.DisplayName); }
public void Parse_Null() { string fullName = null; // ReSharper disable once ExpressionIsAlwaysNull var target = new FullNameParser(fullName); target.Parse(); Assert.Null(target.Title); Assert.Null(target.FirstName); Assert.Null(target.MiddleName); Assert.Null(target.LastName); Assert.Null(target.Suffix); }
public void Parse_JimmySpaceLeeSpaceDabneySpaceII() { var fullName = "Jimmy Lee Dabney II"; var target = new FullNameParser(fullName); target.Parse(); Assert.Equal("Jimmy", target.FirstName); Assert.Equal("Lee", target.MiddleName); Assert.Equal("Dabney", target.LastName); Assert.Equal("II", target.Suffix); Assert.Equal("Jimmy Lee Dabney", target.DisplayName); }
public void Parse_InesDelaCuna() { //ARRANGE var fullName = "Ines De La Cuna"; var target = new FullNameParser(fullName); //ACT target.Parse(); //ASSERT Assert.Equal("Ines", target.FirstName); Assert.Equal("De La Cuna", target.LastName); Assert.Equal("Ines De La Cuna", target.DisplayName); Assert.Null(target.Title); }
/// <summary> /// Parses a full name into its name parts then constructs a new PersonName /// </summary> /// <param name="fullName">The full name to parse</param> /// <returns>The PersonName constructed from the name parts</returns> public static Result <PersonName> Parse(string fullName) { if (String.IsNullOrEmpty(fullName)) { return(Result.Failure <PersonName>("The name must contain a value.")); } else { var parsedName = FullNameParser.Parse(fullName); var firstName = parsedName.FirstName; var middleName = parsedName.MiddleName; var lastName = parsedName.LastName; var title = parsedName.Title; var suffix = parsedName.Suffix; // NOTE: // The name parser works for most names, but there are // some valid edge cases that do not work. // // For example, the name 'Mary Sarah-Jane Lucy' fails // because the middle name contains a hyphen, which the // parser can't handle. // // The following code is a failsafe for these cases. // It simply uses the first and last words as the first // and last names, then anything in between gets treated // as the middle name. if (parsedName.Results.Count == 0) { var names = fullName.Split(' '); firstName = names.FirstOrDefault(); if (names.Length > 1) { lastName = names.LastOrDefault(); } if (names.Length > 2) { middleName = String.Join(" ", names.Skip(1).Take(names.Length - 2)); } } return(Create(firstName, middleName, lastName, title, suffix)); } }
public void AfricanNames_Test(string firstName, string lastName, string expectedDisplayName) { // ARRANGE string fullName = $"{firstName} {lastName}"; //Console.WriteLine(fullName); // ACT var target = new FullNameParser(fullName); target.Parse(); // ASSERT Assert.Equal(firstName, target.FirstName); Assert.Equal(lastName, target.LastName); Assert.Equal(expectedDisplayName, target.DisplayName); }
public void Parse_JohnKennedyIII() { //ARRANGE var fullName = "John Kennedy III"; var target = new FullNameParser(fullName); //ACT target.Parse(); //ASSERT Assert.Equal("John", target.FirstName); Assert.Equal("Kennedy", target.LastName); Assert.Equal("John Kennedy", target.DisplayName); Assert.Null(target.Title); Assert.Equal("III", target.Suffix); }
public void Parse_FirstLastSuffix() { //ARRANGE var fullName = "Michael Crawford III"; var target = new FullNameParser(fullName); //ACT target.Parse(); Assert.Equal("Michael", target.FirstName); Assert.Null(target.MiddleName); Assert.Equal("Crawford", target.LastName); Assert.Equal("III", target.Suffix); Assert.Null(target.Title); Assert.Equal("Michael Crawford", target.DisplayName); }
public void RandomNamesTest() { var g = new PersonNameGenerator(); var firstName = g.GenerateRandomMaleFirstName(); var lastName = g.GenerateRandomLastName(); string fullName = $"{firstName} {lastName}"; Console.WriteLine(fullName); var target = new FullNameParser(fullName); target.Parse(); Assert.AreEqual(firstName, target.FirstName); Assert.AreEqual(lastName, target.LastName); Assert.AreEqual(fullName, target.DisplayName); }
public void Parse_CompanyNamesAsPersonNames() { string[] companyNamesAsPersonNames = { "AL HUGHES (MARINE)", "HI TECH HYDRAULICS (1985) LT", "ALFALFA BEEKEEPERS LTD", "ALAA SALAH AELSAYAD@TORCC." }; foreach (var item in companyNamesAsPersonNames) { Console.WriteLine(item); var fullName = item; var target = new FullNameParser(fullName); target.Parse(); Assert.AreEqual(fullName, target.DisplayName); Assert.IsNull(target.FirstName); Assert.IsNull(target.LastName); Assert.IsNull(target.Title); Assert.IsNull(target.NickName); } }
public void CanadianMPs_Test() { //ARRANGE string title = Convert.ToString(TestContext.DataRow["PersonShortHonorific"]); string firstName = Convert.ToString(TestContext.DataRow["PersonOfficialFirstName"]); string lastName = Convert.ToString(TestContext.DataRow["PersonOfficialLastName"]); string fullName; string expectedDisplayName = $"{firstName} {lastName}"; if (!String.IsNullOrEmpty(title)) { fullName = $"{title} {firstName} {lastName}"; } else { fullName = $"{firstName} {lastName}"; } Console.WriteLine(fullName); //ACT var target = new FullNameParser(fullName); target.Parse(); //ASSERT if (!String.IsNullOrEmpty(title)) { Assert.AreEqual(title, target.Title, "Titles doesn't match"); } else { Assert.IsNull(target.Title, "Title was expected to be null"); } Assert.AreEqual(firstName, target.FirstName, "First Name doesn't match"); Assert.AreEqual(lastName, target.LastName, "Last Name doesn't match"); Assert.AreEqual(expectedDisplayName, target.DisplayName, "DisplayName doesn't match"); }
public void CanadianMPs_Test(string title, string firstName, string lastName) { //ARRANGE var firstNames = firstName.Split(new[] { ' ' }, 2); var firstFirstName = firstNames[0]; var secondFirstName = firstNames.Length == 2 ? firstNames[1] : null; var expectedDisplayName = $"{firstName} {lastName}"; var fullName = !String.IsNullOrEmpty(title) ? $"{title} {expectedDisplayName}" : $"{expectedDisplayName}"; //Console.WriteLine(fullName); //ACT var target = new FullNameParser(fullName); target.Parse(); //ASSERT if (!String.IsNullOrEmpty(title)) { Assert.Equal(title, target.Title); } else { Assert.Null(target.Title); } // Ruth Ellen Brasseau is more likely to be first "Ruth" middle "Ellen" last "Brasseau" // or first "Ruth" last "Ellen Brasseau" than first "Ruth Ellen" last "Brasseau". // It would likely be hyphenated ("Ruth-Elen") or joined ("RuthEllen") in general usage. if (firstName != target.FirstName) { Assert.Equal(firstFirstName, target.FirstName); Assert.Equal(secondFirstName, target.MiddleName); //Assert.Contains(firstName, target.Results.Select(r => r.FirstName)); } //Assert.Equal( firstName, target.FirstName); Assert.Equal(lastName, target.LastName); Assert.Equal(expectedDisplayName, target.DisplayName); }
private bool GetNameParts(string fullname, out string firstName, out string lastName, out string middleName, out string suffixName) { firstName = null; lastName = null; middleName = null; suffixName = null; if (string.IsNullOrWhiteSpace(fullname)) { return(false); } fullname = fullname.Trim(); var target = new FullNameParser(fullname); target.Parse(); firstName = target.FirstName; lastName = target.LastName; middleName = target.MiddleName; suffixName = target.Suffix; return(true); }
public void AfricanNames_Test() { //ARRANGE string firstName = Convert.ToString(TestContext.DataRow["FirstName"]); string lastName = Convert.ToString(TestContext.DataRow["LastName"]); string expectedDisplayName = Convert.ToString(TestContext.DataRow["Name"]); string fullName = $"{firstName} {lastName}"; Console.WriteLine(fullName); //ACT var target = new FullNameParser(fullName); target.Parse(); //ASSERT Assert.AreEqual(firstName, target.FirstName, "First Name doesn't match"); Assert.AreEqual(lastName, target.LastName, "Last Name doesn't match"); Assert.AreEqual(expectedDisplayName, target.DisplayName, "DisplayName doesn't match"); }