コード例 #1
0
ファイル: ExtraCasesTests.cs プロジェクト: selerix/NameParser
        public void Parse_TammySpaceLDotBakerSpaceII()
        {
            var fullName = "Tammy L. Baker II";
            var target   = new FullNameParser(fullName);

            target.Parse();


            Assert.Equal("Tammy", target.FirstName);
            Assert.Equal("L", target.MiddleName);
            Assert.Equal("Baker", target.LastName);
            Assert.Equal("II", target.Suffix);
            Assert.Equal("Tammy L Baker", target.DisplayName);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Parse_MrDOTPasqualeSCOPEPatSCOPEJohnsonJr()
        {
            var fullName = "Mr. Pasquale (Pat) Johnson Jr";
            var target   = new FullNameParser(fullName);

            target.Parse();

            Assert.AreEqual("Mr.", target.Title);
            Assert.AreEqual("Pasquale", target.FirstName);
            Assert.AreEqual("Johnson", target.LastName);
            Assert.AreEqual("Pasquale Johnson", target.DisplayName);
            Assert.AreEqual("Pat", target.NickName);
            Assert.AreEqual("Jr", target.Suffix);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: ExtraCasesTests.cs プロジェクト: selerix/NameParser
        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);
        }
コード例 #6
0
        public void Parse_MrJackFrancisVanDerWaalSr()
        {
            var fullName = "Mr. Jack Francis Van Der Waal Sr.";
            var target   = new FullNameParser(fullName);

            target.Parse();

            Assert.Equal("Mr.", target.Title);
            Assert.Equal("Jack", target.FirstName);
            Assert.Equal("Francis", target.MiddleName);
            Assert.Equal("Van Der Waal", target.LastName);
            Assert.Equal("Sr.", target.Suffix);
            Assert.Equal("Jack Francis Van Der Waal", target.DisplayName);
        }
コード例 #7
0
        public void Parse_SpaceTammySpaceLDotVanSpaceBakerSpaceIISpace()
        {
            var fullName = " Tammy L. van Baker II ";
            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("II", target.Suffix);
            Assert.Equal("Tammy L. van Baker", target.DisplayName);
        }
コード例 #8
0
ファイル: ExtraCasesTests.cs プロジェクト: selerix/NameParser
        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);
        }
コード例 #9
0
        /// <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));
            }
        }
コード例 #10
0
ファイル: ExtraCasesTests.cs プロジェクト: selerix/NameParser
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: ExtraCasesTests.cs プロジェクト: selerix/NameParser
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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");
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        public void FirstMiddlePrefixedLastSuffix()
        {
            var fullName = "EXAMPLE";
            var target   = new FullNameParser(fullName);

            Assert.False(FullNameParser.EnableAutomaticThirdPartyIntegration);

            target.Parse();

            Assert.Equal("EXAMPLE", target.FirstName);
            Assert.Null(target.LastName);
            Assert.Equal("EXAMPLE", target.DisplayName);

            FullNameParser.EnableAutomaticThirdPartyIntegration = true;

            target.Parse();

            Assert.Equal("Success", target.FirstName);
            Assert.Equal("Success", target.LastName);
            Assert.Equal("Success", target.DisplayName);
        }
コード例 #18
0
ファイル: NameParserTest.cs プロジェクト: selerix/NameParser
        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);
        }
コード例 #19
0
        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");
        }