Exemplo n.º 1
0
        public void Test_Common2()
        {
            GDMTree tree = new GDMTree();

            using (GDMFamilyRecord famRec = new GDMFamilyRecord(tree)) {
                Assert.IsNotNull(famRec);

                GDMIndividualRecord unkInd = new GDMIndividualRecord(null);
                unkInd.Sex = GDMSex.svUnknown;
                Assert.IsFalse(famRec.AddSpouse(unkInd));

                GDMIndividualRecord child1 = tree.CreateIndividual(); // for pointer need a proper object
                Assert.IsTrue(famRec.AddChild(child1));

                GDMIndividualRecord child2 = tree.CreateIndividual(); // for pointer need a proper object
                Assert.IsTrue(famRec.AddChild(child2));
                Assert.AreEqual(1, famRec.IndexOfChild(child2));

                famRec.DeleteChild(child1);
                Assert.AreEqual(-1, famRec.IndexOfChild(child1));

                string str = GKUtils.GetFamilyString(famRec, null, null);
                Assert.AreEqual("? - ?", str);

                str = GKUtils.GetFamilyString(famRec, "x", "x");
                Assert.AreEqual("x - x", str);

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

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

                GDMCustomEvent evt = famRec.AddEvent(new GDMFamilyEvent(famRec, (int)GEDCOMTagType.MARR, "01 SEP 1981"));
                Assert.AreEqual(1, famRec.Events.Count);
                Assert.AreEqual(evt, famRec.FindEvent(GEDCOMTagType.MARR));

                using (GDMFamilyRecord famRec2 = new GDMFamilyRecord(tree)) {
                    Assert.AreEqual(0, famRec2.Events.Count);
                    Assert.AreEqual(null, famRec2.FindEvent(GEDCOMTagType.MARR));

                    famRec.MoveTo(famRec2, false);

                    Assert.AreEqual(1, famRec2.Events.Count);
                    Assert.AreEqual(evt, famRec2.FindEvent(GEDCOMTagType.MARR));
                }

                famRec.ResetOwner(tree);
                Assert.AreEqual(tree, famRec.GetTree());
            }
        }
Exemplo n.º 2
0
        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);

            famRec.AddChild(tree.CreateIndividual());
            famRec.AddChild(tree.CreateIndividual());
            famRec.AddChild(tree.CreateIndividual());
            Assert.AreEqual(3, famRec.Children.Count);

            Assert.IsFalse(famRec.IsEmpty());
            famRec.Clear();
            Assert.IsTrue(famRec.IsEmpty());
        }