Пример #1
0
        private static void CompareContext(ISubClassBase expectedList, ISubClassBase actualList)
        {
            var expectedId = expectedList.ClassId;
            var actualId   = actualList.ClassId;

            Assert.AreEqual(expectedId, actualId);
            Assert.AreEqual(expectedList.Count, actualList.Count, "Class " + expectedId + " objects");
            Assert.AreEqual(expectedList.ClassId, actualList.ClassId);
            Assert.AreEqual(expectedList.Definition.SubClass.RefClassId, actualList.Definition.SubClass.RefClassId);
            Assert.AreEqual(expectedList.Reference, expectedList.Reference);
            Assert.AreEqual(expectedList.Definition.SubClass.ToString(), actualList.Definition.SubClass.ToString());
            for (var i = 0; i < expectedList.Count; i++)
            {
                var expectedObject = expectedList[i];
                var actualObject   = actualList[i];
                Assert.AreEqual(expectedObject.ClassId, actualObject.ClassId);
                var expectedAttributes = new GenAttributes(expectedObject.GenDataBase.GenDataDef, expectedObject.ClassId);
                var actualAttributes   = new GenAttributes(actualObject.GenDataBase.GenDataDef, actualObject.ClassId);
                expectedAttributes.GenObject = expectedObject;
                actualAttributes.GenObject   = actualObject;
                Assert.GreaterOrEqual(expectedObject.Attributes.Count, actualObject.Attributes.Count);
                foreach (var property in actualObject.Definition.Properties)
                {
                    Assert.AreEqual(expectedAttributes.AsString(property),
                                    actualAttributes.AsString(property),
                                    property + " " + expectedAttributes.AsString("Name") + " vs " +
                                    actualAttributes.AsString("Name"));
                }

                Assert.AreEqual(expectedObject.SubClass.Count, actualObject.SubClass.Count);
                for (var j = 0; j < actualObject.SubClass.Count; j++)
                {
                    var expectedSubClassName = expectedObject.SubClass[j].Definition.SubClass.Name;
                    var actualSubClassName   = actualObject.SubClass[j].Definition.SubClass.Name;
                    Assert.AreEqual(expectedSubClassName, actualSubClassName);
                    var expectedSubClassDef = expectedObject.GetSubClass(expectedSubClassName).Definition.SubClass;
                    var actualSubClassDef   = actualObject.GetSubClass(actualSubClassName).Definition.SubClass;
                    Assert.AreEqual(expectedSubClassDef.ToString(), actualSubClassDef.ToString());
                    Assert.AreEqual(expectedSubClassDef.ClassId, actualSubClassDef.ClassId);
                    Assert.AreEqual(expectedSubClassDef.IsInherited, actualSubClassDef.IsInherited);
                    Assert.AreEqual(expectedSubClassDef.IsAbstract, actualSubClassDef.IsAbstract);
                    Assert.AreEqual(expectedObject.SubClass[j].ClassId, actualObject.SubClass[j].ClassId);
                    Assert.AreEqual(expectedObject.SubClass[j].Reference, actualObject.SubClass[j].Reference);
                    CompareContext(expectedObject.SubClass[j], actualObject.SubClass[j]);
                }

                Assert.AreEqual(expectedObject.Definition.Inheritors.Count, actualObject.Definition.Inheritors.Count);
                for (var j = 0; j < expectedObject.Definition.Inheritors.Count; j++)
                {
                    var expectedDefInheritor = expectedObject.Definition.Inheritors[j];
                    var actualDefInheritor   = actualObject.Definition.Inheritors[j];
                    Assert.AreEqual(expectedDefInheritor.ClassId, actualDefInheritor.ClassId);
                    Assert.Less(expectedId, expectedDefInheritor.ClassId);
                }
            }
        }
        public void ClassWithPropertyGenDefExtractTest()
        {
            var f = new GenDataDef();

            f.AddClass("", "Class");
            f.AddClass("Class", "Property");
            var d = f.AsGenDataBase();
            var a = new GenAttributes(d.GenDataDef, SubClassClassId);

            Assert.AreEqual(1, d.Root.SubClass.Count);

            Assert.AreEqual(2, d.Root.SubClass[0].Count);

            var c = GetFirstObject(d);

            Assert.AreEqual(2, c.SubClass.Count);
            Assert.AreEqual(2, c.Attributes.Count);
            Assert.AreEqual(ClassClassId, c.ClassId);

            var s = GetFirstObjectOfSubClass(c, "SubClass");

            Assert.AreEqual(1, c.GetSubClass("SubClass").Count);
            a.GenObject = s;
            Assert.AreEqual("Property", a.AsString("Name"));
            Assert.IsNull(GetFirstObjectOfSubClass(c, "Property"));
        }
        public void EmptyClassGenDefExtractTest()
        {
            var f = new GenDataDef();

            f.AddClass("", "Class");
            var d = f.AsGenDataBase();
            var a = new GenAttributes(d.GenDataDef, ClassClassId);

            var r = d.Root;

            Assert.AreEqual(1, r.SubClass.Count);
            Assert.AreEqual(1, r.SubClass[0].Count);

            var c = GetFirstObject(d);

            Assert.AreEqual(2, c.SubClass.Count);
            Assert.AreEqual(2, c.Attributes.Count);

            var s = GetFirstObjectOfSubClass(c, "SubClass");

            Assert.IsNull(s);
            var p = GetFirstObjectOfSubClass(c, "Property");

            Assert.IsNull(p);
            a.GenObject = c;
            Assert.AreEqual("Class", a.AsString("Name"));
        }
        public void ReferenceGenDefExtractTest()
        {
            var fChild  = SetUpParentChildDef("Child", "Grandchild");
            var fParent = SetUpParentChildReferenceDef("Parent", "Child", "ChildDef", fChild);
            var d       = fParent.AsGenDataBase();
            var a       = new GenAttributes(fParent, ClassClassId);

            var c = GetFirstObject(d);

            Assert.AreEqual(1, d.Root.SubClass[0].Count);

            a.GenObject = c;
            Assert.AreEqual("Parent", a.AsString("Name"));
            a = new GenAttributes(d.GenDataDef, SubClassClassId)
            {
                GenObject = GetFirstObjectOfSubClass(c, "SubClass")
            };
            Assert.AreEqual("Child", a.AsString("Name"));
            Assert.AreEqual("ChildDef", a.AsString("Reference"));
        }
Пример #5
0
        protected static void ValidateMinimalData(GenDataBase d)
        {
            Assert.AreEqual("Minimal", d.GenDataDef.DefinitionName);
            Assert.AreEqual(4, d.GenDataDef.Classes.Count);

            //Assert.IsFalse(d.Eol(RootClassId));
            //Assert.IsFalse(d.Eol(ClassClassId));
            //Assert.IsFalse(d.Eol(SubClassClassId));
            //Assert.IsFalse(d.Eol(PropertyClassId));

            //Assert.AreEqual(RootClassId, d.Context[RootClassId].ClassId);
            //Assert.AreEqual(ClassClassId, d.Context[ClassClassId].ClassId);
            //Assert.AreEqual(SubClassClassId, d.Context[SubClassClassId].ClassId);
            //Assert.AreEqual(PropertyClassId, d.Context[PropertyClassId].ClassId);

            //Assert.IsTrue(d.Context[RootClassId].IsFirst());
            //Assert.IsTrue(d.Context[RootClassId].IsLast());
            //Assert.AreEqual(1, d.Context[RootClassId].GenObject.SubClass.Count);

            // Class class tests
            //d.First(ClassClassId);
            var c = GetFirstObject(d);

            Assert.IsNotNull(c);
            Assert.AreNotEqual(0, c.GetSubClass("SubClass").Count);
            Assert.AreNotEqual(0, c.GetSubClass("Property").Count);
            //Assert.IsTrue(d.Context[ClassClassId].IsFirst());
            //Assert.IsTrue(d.Context[SubClassClassId].IsFirst());
            //Assert.IsTrue(d.Context[PropertyClassId].IsFirst());

            var ca = new GenAttributes(d.GenDataDef, ClassClassId);
            var sa = new GenAttributes(d.GenDataDef, SubClassClassId);
            var pa = new GenAttributes(d.GenDataDef, PropertyClassId);

            ca.GenObject = c;
            Assert.AreEqual("Class", ca.AsString("Name"));
            Assert.AreEqual(2, c.SubClass.Count);
            Assert.AreEqual(2, c.GetSubClass("SubClass").Count);
            Assert.AreEqual(2, c.GetSubClass("Property").Count);
            pa.GenObject = c.GetSubClass("Property")[0];
            Assert.AreEqual("Name", pa.AsString("Name"));

            // SubClass class tests - SubClass
            var s = GetFirstObjectOfSubClass(c, "SubClass");

            Assert.IsNotNull(s);
            sa.GenObject = s;
            Assert.AreEqual("SubClass", sa.AsString("Name"));
            Assert.AreEqual(0, s.SubClass.Count);

            // SubClass class tests - Property
            var p = GetNextObjectInSubClass(s);

            Assert.AreEqual(p.GetSubClass("SubClass").Count - 1, p.GetSubClass("SubClass").IndexOf(p));
            sa.GenObject = p;
            Assert.AreEqual("Property", sa.AsString("Name"));
            Assert.AreEqual(0, p.SubClass.Count);

            // SubClass class tests
            s = GetNextObjectInSubClass(c);
            Assert.IsNotNull(s);
            ca.GenObject = s;
            Assert.AreEqual("SubClass", ca.AsString("Name"));
            Assert.AreEqual(0, s.GetSubClass("SubClass").Count);
            Assert.AreEqual(3, s.GetSubClass("Property").Count);
            pa.GenObject = s.GetSubClass("Property")[0];
            Assert.AreEqual("Name", pa.AsString("Name"));
            pa.GenObject = GetNextObjectInSubClass((GenObject)pa.GenObject);
            Assert.AreEqual("Reference", pa.AsString("Name"));
            pa.GenObject = GetNextObjectInSubClass((GenObject)pa.GenObject);
            Assert.AreEqual("Relationship", pa.AsString("Name"));

            // Property class tests
            p = GetNextObjectInSubClass(s);
            Assert.IsNotNull(p);
            ca.GenObject = p;
            Assert.AreEqual("Property", ca.AsString("Name"));
            Assert.AreEqual(0, p.GetSubClass("SubClass").Count);
            Assert.AreEqual(1, p.GetSubClass("Property").Count);
            pa.GenObject = p.GetSubClass("Property")[0];
            Assert.AreEqual("Name", pa.AsString("Name"));
        }
Пример #6
0
        /// <summary>
        /// Create a new <see cref="ClassTreeNode"/> for the selected class
        /// </summary>
        /// <param name="parentNode">The tree node of the parent subclass of this class.</param>
        /// <param name="genDataBase"></param>
        /// <param name="definition">The definition data for the data being navigated.</param>
        /// <param name="classId">The ID of this class.</param>
        /// <param name="genObject"></param>
        public ClassTreeNode(SubClassTreeNode parentNode, GenDataBase genDataBase, Definition definition, int classId, GenObject genObject)
        {
            ClassId       = classId;
            GenDataBase   = genDataBase;
            ParentNode    = parentNode;
            GenObject     = genObject;
            ClassDef      = GenDataBase.GenDataDef.GetClassDef(ClassId);
            Def           = ClassId > definition.ClassList.Count ? null : definition.ClassList[ClassId - 1];
            GenAttributes = new GenAttributes(GenDataBase.GenDataDef, classId)
            {
                GenObject = GenObject
            };

            Text        = ClassDef.Properties.IndexOf("Name") == -1 ? ClassDef.Name : GenAttributes.AsString("Name");
            ImageIndex  = 1;
            ToolTipText = Def == null ? "" : Def.Title;
            Tag         = new GenObjectViewModel(GenObject, Def, ClassDef.IsReference);

            foreach (var subClass in ClassDef.SubClasses)
            {
                Nodes.Add(new SubClassTreeNode(this, GenDataBase, definition, subClass.SubClass.ClassId));
            }
        }