public override float IsMatch(GDMTag tag, MatchParams matchParams) { GDMIndividualRecord indi = tag as GDMIndividualRecord; if (indi == null) { return(0.0f); } if (Sex != indi.Sex) { return(0.0f); } bool womanMode = (Sex == GDMSex.svFemale); float matchesCount = 0.0f; float nameMatch = 0.0f; float birthMatch = 0.0f; float deathMatch = 0.0f; // check name /*for (int i = 0; i < indi.PersonalNames.Count; i++) * { * for (int k = 0; k < fPersonalNames.Count; k++) * { * float currentNameMatch = fPersonalNames[k].IsMatch(indi.PersonalNames[i]); * nameMatch = Math.Max(nameMatch, currentNameMatch); * } * }*/ string iName = GetComparableName(womanMode); string kName = indi.GetComparableName(womanMode); if (!string.IsNullOrEmpty(iName) && !string.IsNullOrEmpty(kName)) { nameMatch = GetStrMatch(iName, kName, matchParams); matchesCount++; } // 0% name match would be pointless checking other details if (nameMatch != 0.0f && matchParams.DatesCheck) { var dates = GetLifeDates(); var indiDates = indi.GetLifeDates(); if (dates.BirthEvent != null && indiDates.BirthEvent != null) { birthMatch = dates.BirthEvent.IsMatch(indiDates.BirthEvent, matchParams); matchesCount++; } else if (dates.BirthEvent == null && indiDates.BirthEvent == null) { birthMatch = 100.0f; matchesCount++; } else { matchesCount++; } /*if (death != null && indiDeath != null) { * deathMatch = death.IsMatch(indiDeath, matchParams); * matches++; * } else if (death == null && indiDeath == null) { * deathMatch = 100.0f; * matches++; * } else { * matches++; * }*/ } float match = (nameMatch + birthMatch + deathMatch) / matchesCount; return(match); }
public void Test_Common() { GDMTree tree = new GDMTree(); Assert.IsNotNull(tree); Assert.IsNotNull(tree.GetSubmitter()); // Tests of event handlers tree.OnChange += OnTreeChange; tree.OnChanging += OnTreeChanging; tree.OnProgress += OnTreeProgress; tree.BeginUpdate(); Assert.IsTrue(tree.IsUpdated()); GDMRecord rec; GDMIndividualRecord iRec = tree.CreateIndividual(); Assert.IsNotNull(iRec, "CreateIndividual() != null"); string xref = iRec.XRef; rec = tree.XRefIndex_Find(xref); Assert.IsNotNull(rec); Assert.AreEqual(xref, rec.XRef); string uid = iRec.UID; rec = tree.FindUID(uid); Assert.IsNotNull(rec); Assert.AreEqual(uid, rec.UID); Assert.IsNull(tree.FindUID("")); // GDMFamilyRecord famRec = tree.CreateFamily(); Assert.IsNotNull(famRec, "CreateFamily() != null"); // GDMNoteRecord noteRec = tree.CreateNote(); Assert.IsNotNull(noteRec, "CreateNote() != null"); // GDMRepositoryRecord repRec = tree.CreateRepository(); Assert.IsNotNull(repRec, "CreateRepository() != null"); // GDMSourceRecord srcRec = tree.CreateSource(); Assert.IsNotNull(srcRec, "CreateSource() != null"); // GDMMultimediaRecord mmRec = tree.CreateMultimedia(); Assert.IsNotNull(mmRec, "CreateMultimedia() != null"); // GDMRecord sbmrRec = tree.AddRecord(new GDMSubmitterRecord(tree)); Assert.IsNotNull(sbmrRec, "sbmrRec != null"); tree.NewXRef(sbmrRec); string submXRef = sbmrRec.XRef; // GDMSubmissionRecord submRec = tree.AddRecord(new GDMSubmissionRecord(tree)) as GDMSubmissionRecord; Assert.IsNotNull(submRec, "rec1 != null"); tree.NewXRef(submRec); // GDMGroupRecord groupRec = tree.CreateGroup(); Assert.IsNotNull(groupRec, "CreateGroup() != null"); // GDMTaskRecord taskRec = tree.CreateTask(); Assert.IsNotNull(taskRec, "CreateTask() != null"); // GDMCommunicationRecord commRec = tree.CreateCommunication(); Assert.IsNotNull(commRec, "CreateCommunication() != null"); // GDMResearchRecord resRec = tree.CreateResearch(); Assert.IsNotNull(resRec, "CreateResearch() != null"); // GDMLocationRecord locRec = tree.CreateLocation(); Assert.IsNotNull(locRec, "CreateLocation() != null"); tree.EndUpdate(); Assert.IsFalse(tree.IsUpdated()); tree.OnChange -= OnTreeChange; tree.OnChanging -= OnTreeChanging; tree.OnProgress -= OnTreeProgress; int size = 0; var enum1 = tree.GetEnumerator(GDMRecordType.rtNone); GDMRecord rec1; enum1.Reset(); while (enum1.MoveNext(out rec1)) { size++; } Assert.AreEqual(14, size); for (int i = 0; i < tree.RecordsCount; i++) { GDMRecord rec2 = tree[i]; Assert.IsNotNull(rec2); string xref2 = rec2.XRef; GDMRecord rec3 = tree.XRefIndex_Find(xref2); Assert.IsNotNull(rec3); Assert.AreEqual(rec2, rec3); /*string uid = rec2.UID; * GEDCOMRecord rec4 = tree.FindUID(uid); * Assert.IsNotNull(rec4); * Assert.AreEqual(rec2, rec4);*/ int idx = tree.IndexOf(rec2); Assert.AreEqual(i, idx); } var recordsX = tree.GetRecords <GDMIndividualRecord>(); Assert.IsNotNull(recordsX); Assert.AreEqual(1, recordsX.Count); int[] stats = tree.GetRecordStats(); Assert.IsNotNull(stats); Assert.AreEqual(14, stats.Length); Assert.IsFalse(tree.IsEmpty); Assert.IsFalse(tree.DeleteFamilyRecord(null)); Assert.IsTrue(tree.DeleteFamilyRecord(famRec)); Assert.IsFalse(tree.DeleteNoteRecord(null)); Assert.IsTrue(tree.DeleteNoteRecord(noteRec)); Assert.IsFalse(tree.DeleteSourceRecord(null)); Assert.IsTrue(tree.DeleteSourceRecord(srcRec)); Assert.IsFalse(tree.DeleteGroupRecord(null)); Assert.IsTrue(tree.DeleteGroupRecord(groupRec)); Assert.IsFalse(tree.DeleteLocationRecord(null)); Assert.IsTrue(tree.DeleteLocationRecord(locRec)); Assert.IsFalse(tree.DeleteResearchRecord(null)); Assert.IsTrue(tree.DeleteResearchRecord(resRec)); Assert.IsFalse(tree.DeleteCommunicationRecord(null)); Assert.IsTrue(tree.DeleteCommunicationRecord(commRec)); Assert.IsFalse(tree.DeleteTaskRecord(null)); Assert.IsTrue(tree.DeleteTaskRecord(taskRec)); Assert.IsFalse(tree.DeleteMediaRecord(null)); Assert.IsTrue(tree.DeleteMediaRecord(mmRec)); Assert.IsFalse(tree.DeleteIndividualRecord(null)); Assert.IsTrue(tree.DeleteIndividualRecord(iRec)); Assert.IsFalse(tree.DeleteRepositoryRecord(null)); Assert.IsTrue(tree.DeleteRepositoryRecord(repRec)); tree.Clear(); Assert.AreEqual(0, tree.RecordsCount); Assert.IsTrue(tree.IsEmpty); tree.State = GDMTreeState.osReady; Assert.AreEqual(GDMTreeState.osReady, tree.State); // Tests of GEDCOMTree.Extract() using (GDMTree tree2 = new GDMTree()) { GDMIndividualRecord iRec2 = tree.AddRecord(new GDMIndividualRecord(tree2)) as GDMIndividualRecord; Assert.IsNotNull(iRec2); tree2.NewXRef(iRec2); tree2.AddRecord(iRec2); int rIdx = tree2.IndexOf(iRec2); Assert.IsTrue(rIdx >= 0); GDMRecord extractedRec = tree2.Extract(rIdx); Assert.AreEqual(iRec2, extractedRec); Assert.IsTrue(tree2.IndexOf(iRec2) < 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); } }
public void Test_Common2() { GDMSourceRecord sourRec = fContext.Tree.CreateSource(); GDMIndividualRecord indiv = fContext.Tree.CreateIndividual(); GDMRepositoryRecord repRec = fContext.Tree.CreateRepository(); Assert.IsNotNull(sourRec.Data); sourRec.ShortTitle = "This is test source"; Assert.AreEqual("This is test source", sourRec.ShortTitle); // sourRec.Originator.Lines.Text = ("author"); Assert.AreEqual("author", sourRec.Originator.Lines.Text); sourRec.Title.Lines.Text = ("title"); Assert.AreEqual("title", sourRec.Title.Lines.Text); sourRec.Publication.Lines.Text = ("publication"); Assert.AreEqual("publication", sourRec.Publication.Lines.Text); sourRec.Text.Lines.Text = ("sample"); Assert.AreEqual("sample", sourRec.Text.Lines.Text); // sourRec.SetOriginatorArray(new string[] { "author1", "author2", "author3", "author4" }); Assert.AreEqual("author1\r\nauthor2\r\nauthor3\r\nauthor4", sourRec.Originator.Lines.Text); sourRec.SetTitleArray(new string[] { "title" }); Assert.AreEqual("title", sourRec.Title.Lines.Text); sourRec.SetPublicationArray(new string[] { "publication" }); Assert.AreEqual("publication", sourRec.Publication.Lines.Text); sourRec.SetTextArray(new string[] { "sample" }); Assert.AreEqual("sample", sourRec.Text.Lines.Text); // GEDCOMRepositoryCitationTest(sourRec, repRec); using (GDMSourceRecord sour2 = fContext.Tree.CreateSource()) { Assert.Throws(typeof(ArgumentException), () => { sour2.Assign(null); }); sour2.Assign(sourRec); string buf = TestUtils.GetTagStreamText(sour2, 0); Assert.AreEqual("0 @S2@ SOUR\r\n" + "1 TITL title\r\n" + "1 PUBL publication\r\n" + "1 ABBR This is test source\r\n" + "1 REPO @R2@\r\n" + "1 AUTH author1\r\n" + "2 CONT author2\r\n" + "2 CONT author3\r\n" + "2 CONT author4\r\n" + "1 TEXT sample\r\n", buf); } sourRec.ReplaceXRefs(new GDMXRefReplacer()); Assert.IsFalse(sourRec.IsEmpty()); sourRec.Clear(); Assert.IsTrue(sourRec.IsEmpty()); }
public void Test_Common() { GDMTree tree = new GDMTree(); Assert.IsNotNull(tree); GDMIndividualRecord indiv = tree.CreateIndividual(); Assert.IsNotNull(indiv); GDMFamilyRecord famRec = tree.CreateFamily(); Assert.IsNotNull(famRec); famRec.Restriction = GDMRestriction.rnLocked; Assert.AreEqual(GDMRestriction.rnLocked, famRec.Restriction); famRec.AddChild(indiv); Assert.AreEqual(0, famRec.IndexOfChild(indiv)); famRec.Husband.Value = tree.CreateIndividual(); famRec.Wife.Value = tree.CreateIndividual(); using (GDMFamilyRecord fam2 = tree.CreateFamily()) { Assert.Throws(typeof(ArgumentException), () => { fam2.Assign(null); }); fam2.Assign(famRec); string buf = TestUtils.GetTagStreamText(fam2, 0); Assert.AreEqual("0 @F2@ FAM\r\n" + "1 RESN locked\r\n" + "1 HUSB @I2@\r\n" + "1 WIFE @I3@\r\n" + "1 CHIL @I1@\r\n", buf); } // Integrity test GDMChildToFamilyLink childLink = indiv.ChildToFamilyLinks[0]; Assert.IsNotNull(childLink.Family); famRec.RemoveChild(indiv); Assert.AreEqual(-1, famRec.IndexOfChild(indiv)); // Assert.Throws(typeof(ArgumentException), () => { famRec.AddEvent(new GDMIndividualEvent(null)); }); famRec.ReplaceXRefs(new GDMXRefReplacer()); // famRec.Husband.Value = indiv; Assert.AreEqual(indiv, famRec.Husband.Individual); famRec.Husband.Value = null; // famRec.Wife.Value = indiv; Assert.AreEqual(indiv, famRec.Wife.Individual); famRec.Wife.Value = null; // indiv.Sex = GDMSex.svMale; famRec.AddSpouse(indiv); Assert.AreEqual(0, indiv.IndexOfSpouse(famRec)); Test_GDMSpouseToFamilyLink(indiv.SpouseToFamilyLinks[0]); Assert.IsNull(famRec.GetSpouseBy(indiv)); famRec.RemoveSpouse(indiv); indiv.Sex = GDMSex.svFemale; famRec.AddSpouse(indiv); Assert.AreEqual(0, indiv.IndexOfSpouse(famRec)); Test_GDMSpouseToFamilyLink(indiv.SpouseToFamilyLinks[0]); Assert.IsNull(famRec.GetSpouseBy(indiv)); famRec.RemoveSpouse(indiv); // famRec.SortChilds(); // famRec.AddChild(null); famRec.RemoveChild(null); famRec.AddSpouse(null); famRec.RemoveSpouse(null); // famRec.AddSpouse(indiv); Assert.IsFalse(famRec.IsEmpty()); famRec.Clear(); Assert.IsTrue(famRec.IsEmpty()); }
public void Test_Common() { using (GDMGroupRecord grpRec = new GDMGroupRecord(fContext.Tree)) { Assert.IsNotNull(grpRec); grpRec.ResetOwner(fContext.Tree); Assert.AreEqual(fContext.Tree, grpRec.GetTree()); } using (GDMGroupRecord groupRec = fContext.Tree.CreateGroup()) { GDMIndividualRecord member = fContext.Tree.XRefIndex_Find("I1") as GDMIndividualRecord; groupRec.GroupName = "Test Group"; Assert.AreEqual("Test Group", groupRec.GroupName); using (GDMGroupRecord group3 = fContext.Tree.CreateGroup()) { var matchParams = new MatchParams(); matchParams.NamesIndistinctThreshold = 100.0f; Assert.AreEqual(0.0f, groupRec.IsMatch(null, matchParams)); group3.GroupName = "Test group"; Assert.AreEqual(100.0f, groupRec.IsMatch(group3, matchParams)); group3.GroupName = "test"; Assert.AreEqual(0.0f, groupRec.IsMatch(group3, matchParams)); } bool res = groupRec.AddMember(null); Assert.IsFalse(res); res = groupRec.RemoveMember(null); Assert.IsFalse(res); Assert.AreEqual(-1, groupRec.IndexOfMember(null)); groupRec.AddMember(member); Assert.AreEqual(0, groupRec.IndexOfMember(member)); using (var group2 = fContext.Tree.CreateGroup()) { Assert.Throws(typeof(ArgumentException), () => { group2.Assign(null); }); group2.Assign(groupRec); string buf = TestUtils.GetTagStreamText(group2, 0); Assert.AreEqual("0 @G4@ _GROUP\r\n" + "1 NAME Test Group\r\n" + "1 _MEMBER @I1@\r\n", buf); } groupRec.RemoveMember(member); Assert.AreEqual(-1, groupRec.IndexOfMember(member)); groupRec.ReplaceXRefs(new GDMXRefReplacer()); Assert.IsFalse(groupRec.IsEmpty()); groupRec.Clear(); Assert.IsTrue(groupRec.IsEmpty()); } }
public void Test_Common() { using (GDMIndividualAttribute customEvent = new GDMIndividualAttribute()) { Assert.IsNotNull(customEvent); Assert.IsNotNull(customEvent.Address); customEvent.Date.ParseString("28 DEC 1990"); string dateTest = "28.12.1990"; Assert.AreEqual(TestUtils.ParseDT(dateTest), customEvent.Date.GetDateTime()); Assert.AreEqual(1990, customEvent.GetChronologicalYear()); Assert.AreEqual(TestUtils.ParseDT(dateTest), customEvent.Date.Date); customEvent.Place.ParseString("Ivanovo"); Assert.AreEqual("Ivanovo", customEvent.Place.StringValue); Assert.IsNotNull(customEvent.Place); customEvent.Agency = "test agency"; Assert.AreEqual("test agency", customEvent.Agency); customEvent.Classification = "test type"; Assert.AreEqual("test type", customEvent.Classification); customEvent.Cause = "test cause"; Assert.AreEqual("test cause", customEvent.Cause); customEvent.ReligiousAffilation = "test aff"; Assert.AreEqual("test aff", customEvent.ReligiousAffilation); customEvent.Restriction = GDMRestriction.rnLocked; Assert.AreEqual(GDMRestriction.rnLocked, customEvent.Restriction); GDMLines strs = new GDMLines("test"); customEvent.PhysicalDescription = strs; Assert.AreEqual(strs.Text, customEvent.PhysicalDescription.Text); customEvent.Address.AddEmailAddress("email"); Assert.AreEqual("email", customEvent.Address.EmailAddresses[0].StringValue); } using (GDMIndividualEvent customEvent = new GDMIndividualEvent()) { Assert.IsNotNull(customEvent); // stream test customEvent.SetName(GEDCOMTagName.BIRT); customEvent.Date.ParseString("20 SEP 1970"); customEvent.Place.StringValue = "test place"; customEvent.Agency = "Agency"; customEvent.Classification = "custom"; customEvent.ReligiousAffilation = "rel_aff"; customEvent.Cause = "Cause"; customEvent.Address.AddressLine1 = "adr1"; customEvent.Restriction = GDMRestriction.rnConfidential; var note = new GDMNotes(); note.Lines.Text = "event notes"; customEvent.Notes.Add(note); var sourCit = new GDMSourceCitation(); sourCit.Description.Text = "event sour desc"; customEvent.SourceCitations.Add(sourCit); var mmLink = new GDMMultimediaLink(); mmLink.Title = "event media title"; customEvent.MultimediaLinks.Add(mmLink); using (GDMIndividualEvent copyEvent = new GDMIndividualEvent()) { Assert.IsNotNull(copyEvent); copyEvent.Assign(customEvent); var iRec = new GDMIndividualRecord(null); iRec.Events.Add(copyEvent); string buf1 = TestUtils.GetTagStreamText(iRec, 0); Assert.AreEqual("0 INDI\r\n" + "1 SEX U\r\n" + "1 BIRT\r\n" + "2 TYPE custom\r\n" + "2 DATE 20 SEP 1970\r\n" + "2 PLAC test place\r\n" + "2 ADDR\r\n" + "3 ADR1 adr1\r\n" + "2 CAUS Cause\r\n" + "2 AGNC Agency\r\n" + "2 RELI rel_aff\r\n" + "2 RESN confidential\r\n" + "2 NOTE event notes\r\n" + "2 SOUR event sour desc\r\n" + "2 OBJE\r\n" + "3 TITL event media title\r\n", buf1); } customEvent.Address.AddEmailAddress("email"); Assert.AreEqual("email", customEvent.Address.EmailAddresses[0].StringValue); } using (GDMFamilyEvent customEvent = new GDMFamilyEvent()) { Assert.IsNotNull(customEvent); customEvent.Address.AddEmailAddress("email"); Assert.AreEqual("email", customEvent.Address.EmailAddresses[0].StringValue); } }
public void Test_Common() { GDMIndividualRecord iRec = fContext.Tree.XRefIndex_Find("I1") as GDMIndividualRecord; Assert.IsNotNull(iRec); GDMFamilyRecord famRec = fContext.Tree.XRefIndex_Find("F1") as GDMFamilyRecord; Assert.IsNotNull(famRec); GDMSourceRecord srcRec = fContext.Tree.XRefIndex_Find("S1") as GDMSourceRecord; Assert.IsNotNull(srcRec); using (GDMTaskRecord taskRec = new GDMTaskRecord(fContext.Tree)) { Assert.IsNotNull(taskRec); taskRec.Priority = GDMResearchPriority.rpNormal; Assert.AreEqual(GDMResearchPriority.rpNormal, taskRec.Priority); taskRec.StartDate.Date = TestUtils.ParseDT("20.01.2013"); Assert.AreEqual(TestUtils.ParseDT("20.01.2013"), taskRec.StartDate.Date); taskRec.StopDate.Date = TestUtils.ParseDT("21.01.2013"); Assert.AreEqual(TestUtils.ParseDT("21.01.2013"), taskRec.StopDate.Date); taskRec.Goal = "Test Goal"; Assert.AreEqual("Test Goal", taskRec.Goal); var goal = taskRec.GetTaskGoal(); Assert.AreEqual(GDMGoalType.gtOther, goal.GoalType); Assert.AreEqual(null, goal.GoalRec); taskRec.Goal = iRec.XRef; goal = taskRec.GetTaskGoal(); Assert.AreEqual(GDMGoalType.gtIndividual, goal.GoalType); Assert.AreEqual(iRec, goal.GoalRec); taskRec.Goal = famRec.XRef; goal = taskRec.GetTaskGoal(); Assert.AreEqual(GDMGoalType.gtFamily, goal.GoalType); Assert.AreEqual(famRec, goal.GoalRec); taskRec.Goal = srcRec.XRef; goal = taskRec.GetTaskGoal(); Assert.AreEqual(GDMGoalType.gtSource, goal.GoalType); Assert.AreEqual(srcRec, goal.GoalRec); using (GDMTaskRecord task2 = fContext.Tree.CreateTask()) { Assert.Throws(typeof(ArgumentException), () => { task2.Assign(null); }); task2.Assign(taskRec); // FIXME: goal format invalid! string buf = TestUtils.GetTagStreamText(task2, 0); Assert.AreEqual("0 @TK2@ _TASK\r\n" + "1 _STARTDATE 20 JAN 2013\r\n" + "1 _STOPDATE 21 JAN 2013\r\n" + "1 _PRIORITY normal\r\n" + "1 _GOAL S1\r\n", buf); } taskRec.ReplaceXRefs(new GDMXRefReplacer()); Assert.IsFalse(taskRec.IsEmpty()); taskRec.Clear(); Assert.IsTrue(taskRec.IsEmpty()); } }
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); // var note = new GDMNotes(persName); note.Lines.Text = "persname notes"; persName.Notes.Add(note); var sourCit = new GDMSourceCitation(persName); sourCit.Description.Text = "persname sour desc"; persName.SourceCitations.Add(sourCit); // 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 NOTE persname notes\r\n" + "2 SOUR persname sour desc\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 NOTE persname notes\r\n" + "2 SOUR persname sour desc\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); } }
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(fContext.Tree.GetParentsFamily(ind3)); GDMIndividualRecord ind2 = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord; Assert.IsNotNull(fContext.Tree.GetMarriageFamily(ind2)); // TODO: transfer to BaseContext tests GDMIndividualRecord indiRec = fContext.Tree.XRefIndex_Find("I4") as GDMIndividualRecord; Assert.IsNull(fContext.GetMarriageFamily(indiRec, false)); Assert.IsNotNull(fContext.GetMarriageFamily(indiRec, 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.Associations); Assert.IsNotNull(indiRec.UserReferences); // for GEDCOMRecord Assert.Throws(typeof(ArgumentException), () => { indiRec.AddEvent(new GDMFamilyEvent()); }); GDMIndividualRecord father, mother; fContext.Tree.GetParents(indiRec, out father, out mother); 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); }); 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, fContext.Tree.GetPtrValue <GDMMultimediaRecord>(mmLink)); 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(fContext.Tree, indi); // test with empty PersonalNames Assert.AreEqual("", parts.Surname); Assert.AreEqual("", parts.Name); Assert.AreEqual("", parts.Patronymic); indi.AddPersonalName(new GDMPersonalName()); // test with empty Name parts = GKUtils.GetNameParts(fContext.Tree, 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.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(fContext.Tree.GetParentsFamily(indi)); // TODO: move to BaseContext tests Assert.IsNotNull(fContext.GetParentsFamily(indi, true)); // MoveTo test GDMIndividualRecord ind = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord; indi.AddAssociation("test", ind); using (GDMIndividualRecord indi3 = new GDMIndividualRecord(fContext.Tree)) { indi.MoveTo(indi3); st = GKUtils.GetNameString(indi3, true, true); Assert.AreEqual("Petrov Ivan [BigHead]", st); } indi.ResetTree(fContext.Tree); } indiRec.ReplaceXRefs(new GDMXRefReplacer()); fContext.Tree.SortSpouses(indiRec); Assert.AreEqual(0, fContext.Tree.GetTotalChildrenCount(indiRec)); }
public void Test_Common() { using (GDMAddress addr = new GDMAddress()) { Assert.IsNotNull(addr, "addr != null"); addr.SetAddressText("test"); Assert.AreEqual("test", addr.Lines.Text.Trim()); addr.Lines.Text = "This\r\naddress\r\ntest"; Assert.AreEqual("This\r\naddress\r\ntest", addr.Lines.Text.Trim()); Assert.AreEqual("This", addr.Lines[0]); Assert.AreEqual("address", addr.Lines[1]); Assert.AreEqual("test", addr.Lines[2]); addr.AddPhoneNumber("8 911 101 99 99"); Assert.AreEqual("8 911 101 99 99", addr.PhoneNumbers[0].StringValue); addr.AddEmailAddress("*****@*****.**"); Assert.AreEqual("*****@*****.**", addr.EmailAddresses[0].StringValue); addr.AddFaxNumber("abrakadabra"); Assert.AreEqual("abrakadabra", addr.FaxNumbers[0].StringValue); addr.AddWebPage("http://test.com"); Assert.AreEqual("http://test.com", addr.WebPages[0].StringValue); addr.AddPhoneNumber("8 911 101 33 33"); Assert.AreEqual("8 911 101 33 33", addr.PhoneNumbers[1].StringValue); addr.AddEmailAddress("*****@*****.**"); Assert.AreEqual("*****@*****.**", addr.EmailAddresses[1].StringValue); addr.AddFaxNumber("abrakadabra"); Assert.AreEqual("abrakadabra", addr.FaxNumbers[1].StringValue); addr.AddWebPage("http://test.ru"); Assert.AreEqual("http://test.ru", addr.WebPages[1].StringValue); // addr.AddressLine1 = "test1"; Assert.AreEqual("test1", addr.AddressLine1); addr.AddressLine2 = "test2"; Assert.AreEqual("test2", addr.AddressLine2); addr.AddressLine3 = "test3"; Assert.AreEqual("test3", addr.AddressLine3); addr.AddressCity = "test4"; Assert.AreEqual("test4", addr.AddressCity); addr.AddressState = "test5"; Assert.AreEqual("test5", addr.AddressState); addr.AddressCountry = "test6"; Assert.AreEqual("test6", addr.AddressCountry); addr.AddressPostalCode = "test7"; Assert.AreEqual("test7", addr.AddressPostalCode); using (GDMAddress addr2 = new GDMAddress()) { Assert.Throws(typeof(ArgumentException), () => { addr2.Assign(null); }); addr2.Assign(addr); var iRec = new GDMIndividualRecord(null); var evt = new GDMIndividualEvent(); evt.SetName("BIRT"); iRec.Events.Add(evt); evt.Address.Assign(addr); string buf = TestUtils.GetTagStreamText(iRec, 0); Assert.AreEqual("0 INDI\r\n" + "1 SEX U\r\n" + "1 BIRT\r\n" + "2 ADDR This\r\n" + "3 CONT address\r\n" + "3 CONT test\r\n" + "3 ADR1 test1\r\n" + "3 ADR2 test2\r\n" + "3 ADR3 test3\r\n" + "3 CITY test4\r\n" + "3 STAE test5\r\n" + "3 CTRY test6\r\n" + "3 POST test7\r\n" + "2 PHON 8 911 101 99 99\r\n" + "2 PHON 8 911 101 33 33\r\n" + "2 EMAIL [email protected]\r\n" + "2 EMAIL [email protected]\r\n" + "2 FAX abrakadabra\r\n" + "2 FAX abrakadabra\r\n" + "2 WWW http://test.com\r\n" + "2 WWW http://test.ru\r\n", buf); Assert.AreEqual("This\r\naddress\r\ntest", addr2.Lines.Text.Trim()); Assert.AreEqual("8 911 101 99 99", addr2.PhoneNumbers[0].StringValue); Assert.AreEqual("*****@*****.**", addr2.EmailAddresses[0].StringValue); Assert.AreEqual("abrakadabra", addr2.FaxNumbers[0].StringValue); Assert.AreEqual("http://test.com", addr2.WebPages[0].StringValue); Assert.AreEqual("8 911 101 33 33", addr2.PhoneNumbers[1].StringValue); Assert.AreEqual("*****@*****.**", addr2.EmailAddresses[1].StringValue); Assert.AreEqual("abrakadabra", addr2.FaxNumbers[1].StringValue); Assert.AreEqual("http://test.ru", addr2.WebPages[1].StringValue); Assert.AreEqual("test1", addr2.AddressLine1); Assert.AreEqual("test2", addr2.AddressLine2); Assert.AreEqual("test3", addr2.AddressLine3); Assert.AreEqual("test4", addr2.AddressCity); Assert.AreEqual("test5", addr2.AddressState); Assert.AreEqual("test6", addr2.AddressCountry); Assert.AreEqual("test7", addr2.AddressPostalCode); } addr.SetAddressArray(new string[] { "test11", "test21", "test31" }); Assert.AreEqual("test11", addr.Lines[0]); Assert.AreEqual("test21", addr.Lines[1]); Assert.AreEqual("test31", addr.Lines[2]); Assert.IsFalse(addr.IsEmpty()); addr.Clear(); Assert.IsTrue(addr.IsEmpty()); } }