Beispiel #1
0
        public void Test_Common()
        {
            GDMIndividualRecord iRec = fContext.Tree.XRefIndex_Find("I1") as GDMIndividualRecord;
            GDMCustomEvent      evt, evtd;

            GEDCOMRecordTest(iRec);

            evt = iRec.FindEvent(GEDCOMTagType.BIRT);
            Assert.IsNotNull(evt);

            evtd = iRec.FindEvent(GEDCOMTagType.DEAT);
            Assert.IsNotNull(evtd);

            Assert.IsFalse(iRec.IsLive());

            GDMIndividualRecord ind3 = fContext.Tree.XRefIndex_Find("I3") as GDMIndividualRecord;

            Assert.IsNotNull(ind3.GetParentsFamily());

            GDMIndividualRecord ind2 = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord;

            Assert.IsNotNull(ind2.GetMarriageFamily());

            //
            GDMIndividualRecord indiRec = fContext.Tree.XRefIndex_Find("I4") as GDMIndividualRecord;

            Assert.IsNull(indiRec.GetMarriageFamily());
            Assert.IsNotNull(indiRec.GetMarriageFamily(true));

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

            indiRec.AutomatedRecordID = "test11";
            Assert.AreEqual("test11", indiRec.AutomatedRecordID);

            Assert.AreEqual(GDMRecordType.rtIndividual, indiRec.RecordType);

            Assert.AreEqual(4, indiRec.GetId());
            Assert.AreEqual("4", indiRec.GetXRefNum());

            Assert.AreEqual(-1, indiRec.IndexOfSource(null));

            indiRec.AddUserRef("test userref");
            Assert.AreEqual("test userref", indiRec.UserReferences[0].StringValue);

            //
            Assert.IsNotNull(indiRec.Aliases);
            Assert.IsNotNull(indiRec.Associations);
            Assert.IsNotNull(indiRec.UserReferences); // for GEDCOMRecord

            Assert.Throws(typeof(ArgumentException), () => {
                indiRec.AddEvent(new GDMFamilyEvent(null));
            });

            GDMIndividualRecord father, mother;
            GDMFamilyRecord     fam = indiRec.GetParentsFamily();

            if (fam == null)
            {
                father = null;
                mother = null;
            }
            else
            {
                father = fam.Husband.Individual;
                mother = fam.Wife.Individual;
            }

            Assert.IsNull(father);
            Assert.IsNull(mother);

            indiRec.Sex = GDMSex.svMale;
            Assert.AreEqual(GDMSex.svMale, indiRec.Sex);

            indiRec.Restriction = GDMRestriction.rnLocked;
            Assert.AreEqual(GDMRestriction.rnLocked, indiRec.Restriction);

            indiRec.Patriarch = true;
            Assert.AreEqual(true, indiRec.Patriarch);
            indiRec.Patriarch = false;
            Assert.AreEqual(false, indiRec.Patriarch);

            indiRec.Bookmark = true;
            Assert.AreEqual(true, indiRec.Bookmark);
            indiRec.Bookmark = false;
            Assert.AreEqual(false, indiRec.Bookmark);

            Assert.Throws(typeof(ArgumentException), () => { indiRec.MoveTo(null, false); });

            using (GDMIndividualRecord copyIndi = new GDMIndividualRecord(null)) {
                Assert.IsNotNull(copyIndi);

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

                copyIndi.Assign(indiRec);
                Assert.AreEqual(100.0f, indiRec.IsMatch(copyIndi, new MatchParams()));
            }


            Assert.IsFalse(indiRec.IsEmpty());
            indiRec.Clear();
            Assert.IsTrue(indiRec.IsEmpty());

            float ca = indiRec.GetCertaintyAssessment();

            Assert.AreEqual(0.0f, ca);


            Assert.IsNull(indiRec.GetPrimaryMultimediaLink());
            GDMMultimediaLink mmLink = indiRec.SetPrimaryMultimediaLink(null);

            Assert.IsNull(mmLink);
            GDMMultimediaRecord mmRec = fContext.Tree.CreateMultimedia();

            mmLink = indiRec.SetPrimaryMultimediaLink(mmRec);
            Assert.IsNotNull(mmLink);
            mmLink = indiRec.GetPrimaryMultimediaLink();
            Assert.AreEqual(mmRec, mmLink.Value);


            Assert.AreEqual(-1, indiRec.IndexOfGroup(null));
            Assert.AreEqual(-1, indiRec.IndexOfSpouse(null));


            GDMIndividualRecord indi2 = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord;
            GDMAssociation      asso  = indiRec.AddAssociation("test", indi2);

            Assert.IsNotNull(asso);

            using (GDMIndividualRecord indi = new GDMIndividualRecord(fContext.Tree)) {
                Assert.IsNotNull(indi);

                var parts = GKUtils.GetNameParts(indi); // test with empty PersonalNames
                Assert.AreEqual("", parts.Surname);
                Assert.AreEqual("", parts.Name);
                Assert.AreEqual("", parts.Patronymic);

                indi.AddPersonalName(new GDMPersonalName(indi)); // test with empty Name
                parts = GKUtils.GetNameParts(indi);
                Assert.AreEqual("", parts.Surname);
                Assert.AreEqual("", parts.Name);
                Assert.AreEqual("", parts.Patronymic);
                indi.PersonalNames.Clear();

                string st;
                Assert.AreEqual("", GKUtils.GetNameString(indi, true, false));
                Assert.AreEqual("", GKUtils.GetNickString(indi));

                GDMPersonalName pName = new GDMPersonalName(indi);
                indi.AddPersonalName(pName);
                pName.Pieces.Nickname = "BigHead";
                pName.SetNameParts("Ivan", "Petrov", "");

                st = GKUtils.GetNameString(indi, true, true);
                Assert.AreEqual("Petrov Ivan [BigHead]", st);
                st = GKUtils.GetNameString(indi, false, true);
                Assert.AreEqual("Ivan Petrov [BigHead]", st);
                Assert.AreEqual("BigHead", GKUtils.GetNickString(indi));

                Assert.IsNull(indi.GetParentsFamily());
                Assert.IsNotNull(indi.GetParentsFamily(true));

                // MoveTo test
                GDMIndividualRecord ind = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord;

                indi.AddAssociation("test", ind);
                indi.Aliases.Add(new GDMAlias(indi));

                using (GDMIndividualRecord indi3 = new GDMIndividualRecord(fContext.Tree)) {
                    indi.MoveTo(indi3, false);

                    st = GKUtils.GetNameString(indi3, true, true);
                    Assert.AreEqual("Petrov Ivan [BigHead]", st);
                }

                indi.ResetOwner(fContext.Tree);
                Assert.AreEqual(fContext.Tree, indi.GetTree());
            }

            indiRec.ReplaceXRefs(new GDMXRefReplacer());
        }
Beispiel #2
0
        public override void MoveTo(GDMRecord targetRecord, bool clearDest)
        {
            GDMIndividualRecord targetIndi = targetRecord as GDMIndividualRecord;

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

            /*if (!clearDest) {
             *  DeleteTag(GEDCOMTagType.SEX);
             *  DeleteTag(GEDCOMTagType._UID);
             * }*/

            base.MoveTo(targetRecord, clearDest);

            targetIndi.Sex = fSex;

            while (fPersonalNames.Count > 0)
            {
                GDMPersonalName obj = fPersonalNames.Extract(0);
                obj.ResetOwner(targetIndi);
                targetIndi.AddPersonalName(obj);
            }

            string currentXRef = this.XRef;
            string targetXRef  = targetRecord.XRef;

            while (fChildToFamilyLinks.Count > 0)
            {
                GDMChildToFamilyLink ctfLink = fChildToFamilyLinks.Extract(0);
                GDMFamilyRecord      family  = ctfLink.Family;

                int num = family.Children.Count;
                for (int i = 0; i < num; i++)
                {
                    GDMIndividualLink childPtr = family.Children[i];

                    if (childPtr.XRef == currentXRef)
                    {
                        childPtr.XRef = targetXRef;
                    }
                }

                ctfLink.ResetOwner(targetIndi);
                targetIndi.ChildToFamilyLinks.Add(ctfLink);
            }

            while (fSpouseToFamilyLinks.Count > 0)
            {
                GDMSpouseToFamilyLink stfLink = fSpouseToFamilyLinks.Extract(0);
                GDMFamilyRecord       family  = stfLink.Family;

                if (family.Husband.XRef == currentXRef)
                {
                    family.Husband.XRef = targetXRef;
                }
                else if (family.Wife.XRef == currentXRef)
                {
                    family.Wife.XRef = targetXRef;
                }

                stfLink.ResetOwner(targetIndi);
                targetIndi.SpouseToFamilyLinks.Add(stfLink);
            }

            while (fAssociations.Count > 0)
            {
                GDMAssociation obj = fAssociations.Extract(0);
                obj.ResetOwner(targetIndi);
                targetIndi.Associations.Add(obj);
            }

            while (fAliases.Count > 0)
            {
                GDMAlias obj = fAliases.Extract(0);
                obj.ResetOwner(targetIndi);
                targetIndi.Aliases.Add(obj);
            }

            while (fGroups.Count > 0)
            {
                GDMPointer obj = fGroups.Extract(0);
                obj.ResetOwner(targetIndi);
                targetIndi.Groups.Add(obj);
            }
        }
Beispiel #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());
        }
        public override void MoveTo(GDMRecord targetRecord)
        {
            GDMIndividualRecord targetIndi = targetRecord as GDMIndividualRecord;

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

            base.MoveTo(targetRecord);

            targetIndi.Sex = fSex;

            while (fPersonalNames.Count > 0)
            {
                GDMPersonalName obj = fPersonalNames.Extract(0);
                targetIndi.AddPersonalName(obj);
            }

            string currentXRef = this.XRef;
            string targetXRef  = targetRecord.XRef;

            while (fChildToFamilyLinks.Count > 0)
            {
                GDMChildToFamilyLink ctfLink = fChildToFamilyLinks.Extract(0);
                var family = fTree.GetPtrValue <GDMFamilyRecord>(ctfLink);

                int num = family.Children.Count;
                for (int i = 0; i < num; i++)
                {
                    GDMIndividualLink childPtr = family.Children[i];

                    if (childPtr.XRef == currentXRef)
                    {
                        childPtr.XRef = targetXRef;
                    }
                }

                targetIndi.ChildToFamilyLinks.Add(ctfLink);
            }

            while (fSpouseToFamilyLinks.Count > 0)
            {
                GDMSpouseToFamilyLink stfLink = fSpouseToFamilyLinks.Extract(0);
                var family = fTree.GetPtrValue <GDMFamilyRecord>(stfLink);

                if (family.Husband.XRef == currentXRef)
                {
                    family.Husband.XRef = targetXRef;
                }
                else if (family.Wife.XRef == currentXRef)
                {
                    family.Wife.XRef = targetXRef;
                }

                targetIndi.SpouseToFamilyLinks.Add(stfLink);
            }

            while (fAssociations.Count > 0)
            {
                GDMAssociation obj = fAssociations.Extract(0);
                targetIndi.Associations.Add(obj);
            }

            while (fGroups.Count > 0)
            {
                GDMPointer obj = fGroups.Extract(0);
                targetIndi.Groups.Add(obj);
            }
        }