Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        public void Test_Common()
        {
            // check match
            using (GDMSourceRecord src1 = new GDMSourceRecord(fContext.Tree)) {
                Assert.IsNotNull(src1, "src1 != null");

                Assert.Throws(typeof(ArgumentNullException), () => {
                    src1.RemoveRepository(null);
                });

                using (GDMSourceRecord src2 = new GDMSourceRecord(fContext.Tree)) {
                    Assert.IsNotNull(src2, "src2 != null");

                    Assert.AreEqual(0.0f, src1.IsMatch(null, new MatchParams()));

                    // empty records
                    Assert.AreEqual(100.0f, src1.IsMatch(src2, new MatchParams()));

                    // filled records
                    src1.ShortTitle = "test source";
                    src2.ShortTitle = "test source";
                    Assert.AreEqual(100.0f, src1.IsMatch(src2, new MatchParams()));
                }

                src1.ResetTree(fContext.Tree);
            }

            // check move
            using (GDMSourceRecord src1 = new GDMSourceRecord(fContext.Tree)) {
                Assert.Throws(typeof(ArgumentException), () => {
                    src1.MoveTo(null);
                });

                // fill the record
                src1.ShortTitle             = "test source";
                src1.Title.Lines.Text       = ("test title");
                src1.Originator.Lines.Text  = ("test author");
                src1.Publication.Lines.Text = ("test publ");
                src1.Text.Lines.Text        = ("test text");

                Assert.AreEqual("test source", src1.ShortTitle);
                Assert.AreEqual("test title", src1.Title.Lines.Text);
                Assert.AreEqual("test author", src1.Originator.Lines.Text);
                Assert.AreEqual("test publ", src1.Publication.Lines.Text);
                Assert.AreEqual("test text", src1.Text.Lines.Text);

                src1.ReplaceXRefs(new GDMXRefReplacer());

                GDMRepositoryRecord repRec = fContext.Tree.CreateRepository();
                repRec.RepositoryName = "test repository";
                src1.AddRepository(repRec);
                Assert.AreEqual(1, src1.RepositoryCitations.Count);

                using (GDMSourceRecord src2 = new GDMSourceRecord(fContext.Tree)) {
                    src2.ShortTitle = "test source 2"; // title isn't replaced

                    Assert.AreEqual(0, src2.RepositoryCitations.Count);

                    src1.MoveTo(src2);

                    Assert.AreEqual("test source 2", src2.ShortTitle);

                    Assert.AreEqual("test title", src2.Title.Lines.Text);
                    Assert.AreEqual("test author", src2.Originator.Lines.Text);
                    Assert.AreEqual("test publ", src2.Publication.Lines.Text);
                    Assert.AreEqual("test text", src2.Text.Lines.Text);

                    Assert.AreEqual(1, src2.RepositoryCitations.Count);
                }
            }
        }
Exemplo n.º 4
0
        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 = GKUtils.GetTaskGoal(fContext.Tree, taskRec);
                Assert.AreEqual(GDMGoalType.gtOther, goal.GoalType);
                Assert.AreEqual(null, goal.GoalRec);

                taskRec.Goal = iRec.XRef;
                goal         = GKUtils.GetTaskGoal(fContext.Tree, taskRec);
                Assert.AreEqual(GDMGoalType.gtIndividual, goal.GoalType);
                Assert.AreEqual(iRec, goal.GoalRec);

                taskRec.Goal = famRec.XRef;
                goal         = GKUtils.GetTaskGoal(fContext.Tree, taskRec);
                Assert.AreEqual(GDMGoalType.gtFamily, goal.GoalType);
                Assert.AreEqual(famRec, goal.GoalRec);

                taskRec.Goal = srcRec.XRef;
                goal         = GKUtils.GetTaskGoal(fContext.Tree, taskRec);
                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());
            }
        }
Exemplo n.º 5
0
        private static void GEDCOMRepositoryCitationTest(GDMSourceRecord sourRec, GDMRepositoryRecord repRec)
        {
            GDMRepositoryCitation repCit = sourRec.AddRepository(repRec);

            Assert.IsFalse(repCit.IsEmpty(), "repCit.IsEmpty()"); // its pointer
        }