Ejemplo n.º 1
0
        public void Test_Assign()
        {
            GDMPersonalName instance = new GDMPersonalName(null);

            GDMTag source = null;

            Assert.Throws(typeof(ArgumentException), () => {
                instance.Assign(source);
            });
        }
Ejemplo n.º 2
0
        public override void Assign(GDMTag source)
        {
            GDMIndividualRecord sourceRec = source as GDMIndividualRecord;

            if (sourceRec == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "source");
            }

            base.Assign(source);

            fSex = sourceRec.fSex;

            foreach (GDMPersonalName srcName in sourceRec.fPersonalNames)
            {
                GDMPersonalName copyName = new GDMPersonalName(this);
                copyName.Assign(srcName);
                AddPersonalName(copyName);
            }
        }
Ejemplo n.º 3
0
        public void Test_Common()
        {
            GDMIndividualRecord iRec = fContext.Tree.XRefIndex_Find("I1") as GDMIndividualRecord;

            GDMPersonalName pName = iRec.PersonalNames[0];

            Assert.AreEqual("Ivanov", pName.Surname);
            Assert.AreEqual("Ivan Ivanovich", pName.FirstPart);

            pName.SetNameParts("Ivan Ivanovich", "Ivanov", "testLastPart");
            Assert.AreEqual("Ivanov", pName.Surname);
            Assert.AreEqual("Ivan Ivanovich", pName.FirstPart);
            Assert.AreEqual("testLastPart", pName.LastPart);

//            GEDCOMPersonalNamePieces pieces = pName.Pieces;
//            Assert.AreEqual(pieces.Surname, "surname");
//            Assert.AreEqual(pieces.Name, "name");
//            Assert.AreEqual(pieces.PatronymicName, "patr");

            var parts = GKUtils.GetNameParts(iRec);

            Assert.AreEqual("Ivanov", parts.Surname);
            Assert.AreEqual("Ivan", parts.Name);
            Assert.AreEqual("Ivanovich", parts.Patronymic);


            GDMPersonalName persName = new GDMPersonalName(iRec);

            iRec.AddPersonalName(persName);

            persName          = iRec.PersonalNames[0];
            persName.NameType = GDMNameType.ntBirth;
            Assert.AreEqual(GDMNameType.ntBirth, persName.NameType);

            //

            persName.SetNameParts("Petr", "Ivanov", "Fedoroff");

            //persName.Surname = "Ivanov";
            Assert.AreEqual("Petr", persName.FirstPart);
            Assert.AreEqual("Ivanov", persName.Surname);
            Assert.AreEqual("Fedoroff", persName.LastPart);

            Assert.AreEqual("Petr Ivanov Fedoroff", persName.FullName);

            persName.FirstPart = "Petr";
            Assert.AreEqual("Petr", persName.FirstPart);

            persName.Surname = "Test";
            Assert.AreEqual("Test", persName.Surname);

            persName.LastPart = "Fedoroff";
            Assert.AreEqual("Fedoroff", persName.LastPart);

            //

            GDMPersonalNamePieces pnPieces = persName.Pieces;

            pnPieces.Prefix = "Prefix";
            Assert.AreEqual("Prefix", pnPieces.Prefix);

            pnPieces.Given = "Given";
            Assert.AreEqual("Given", pnPieces.Given);

            pnPieces.Nickname = "Nickname";
            Assert.AreEqual("Nickname", pnPieces.Nickname);

            pnPieces.SurnamePrefix = "SurnamePrefix";
            Assert.AreEqual("SurnamePrefix", pnPieces.SurnamePrefix);

            pnPieces.Surname = "Surname";
            Assert.AreEqual("Surname", pnPieces.Surname);

            pnPieces.Suffix = "Suffix";
            Assert.AreEqual("Suffix", pnPieces.Suffix);

            pnPieces.PatronymicName = "PatronymicName";
            Assert.AreEqual("PatronymicName", pnPieces.PatronymicName);

            pnPieces.MarriedName = "MarriedName";
            Assert.AreEqual("MarriedName", pnPieces.MarriedName);

            pnPieces.ReligiousName = "ReligiousName";
            Assert.AreEqual("ReligiousName", pnPieces.ReligiousName);

            pnPieces.CensusName = "CensusName";
            Assert.AreEqual("CensusName", pnPieces.CensusName);

            Assert.Throws(typeof(ArgumentException), () => {
                pnPieces.Assign(null);
            });

            //

            Assert.AreEqual(GDMLanguageID.Unknown, persName.Language);
            persName.Language = GDMLanguageID.English;
            Assert.AreEqual(GDMLanguageID.English, persName.Language);
            persName.Language = GDMLanguageID.Unknown;
            Assert.AreEqual(GDMLanguageID.Unknown, persName.Language);
            persName.Language = GDMLanguageID.Polish;
            Assert.AreEqual(GDMLanguageID.Polish, persName.Language);

            //

            string buf = TestUtils.GetTagStreamText(persName, 1);

            Assert.AreEqual("1 NAME Petr /Test/ Fedoroff\r\n" +
                            "2 LANG Polish\r\n" + // extension
                            "2 TYPE birth\r\n" +
                            "2 SURN Surname\r\n" +
                            "2 GIVN Given\r\n" +
                            "2 _PATN PatronymicName\r\n" +
                            "2 NPFX Prefix\r\n" +
                            "2 NICK Nickname\r\n" +
                            "2 SPFX SurnamePrefix\r\n" +
                            "2 NSFX Suffix\r\n" +
                            "2 _MARN MarriedName\r\n" +
                            "2 _RELN ReligiousName\r\n" +
                            "2 _CENN CensusName\r\n", buf);

            persName.Language = GDMLanguageID.Unknown;

            using (GDMPersonalName nameCopy = new GDMPersonalName(iRec)) {
                Assert.Throws(typeof(ArgumentException), () => { nameCopy.Assign(null); });

                iRec.AddPersonalName(nameCopy);
                nameCopy.Assign(persName);

                string buf2 = TestUtils.GetTagStreamText(nameCopy, 1);
                Assert.AreEqual("1 NAME Petr /Test/ Fedoroff\r\n" +
                                "2 TYPE birth\r\n" +
                                "2 SURN Surname\r\n" +
                                "2 GIVN Given\r\n" +
                                "2 _PATN PatronymicName\r\n" +
                                "2 NPFX Prefix\r\n" +
                                "2 NICK Nickname\r\n" +
                                "2 SPFX SurnamePrefix\r\n" +
                                "2 NSFX Suffix\r\n" +
                                "2 _MARN MarriedName\r\n" +
                                "2 _RELN ReligiousName\r\n" +
                                "2 _CENN CensusName\r\n", buf2);

                iRec.PersonalNames.Delete(nameCopy);
            }

            using (GDMPersonalName name1 = new GDMPersonalName(null)) {
                Assert.AreEqual("", name1.FirstPart);
                Assert.AreEqual("", name1.Surname);

                Assert.AreEqual(0.0f, name1.IsMatch(null, false));

                using (GDMPersonalName name2 = new GDMPersonalName(null)) {
                    Assert.AreEqual(0.0f, name1.IsMatch(name2, false));

                    name1.SetNameParts("Ivan", "Dub", "");
                    name2.SetNameParts("Ivan", "Dub", "");
                    Assert.AreEqual(100.0f, name1.IsMatch(name2, false));

                    name1.SetNameParts("Ivan", "Dub", "");
                    name2.SetNameParts("Ivan", "Dub2", "");
                    Assert.AreEqual(12.5f, name1.IsMatch(name2, false));

                    name1.SetNameParts("Ivan", "Dub", "");
                    name2.SetNameParts("Ivan2", "Dub", "");
                    Assert.AreEqual(50.0f, name1.IsMatch(name2, false));
                }
            }

            persName.ResetOwner(fContext.Tree);
            Assert.AreEqual(fContext.Tree, persName.GetTree());

            persName.Clear();
            Assert.IsTrue(persName.IsEmpty());
        }