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"));
        }
Example #2
0
        private static GenDataBase SetUpSegmentSeparatorData(string display)
        {
            var fm = GenDataDef.CreateMinimal();
            var dm = new GenDataBase(fm);
            var td = CreateClass(dm, "TestData");

            CreateProperty("Name", td);
            CreateProperty("Display", td);
            var f = dm.AsDef();
            var a = new GenAttributes(f, 1);
            var d = new GenDataBase(f);

            a.GenObject = CreateGenObject(d.Root, "TestData", "One");
            a.SetString("Name", "One");
            a.SetString("Display", display[0] == '1' ? "True" : "");
            a.SaveFields();
            a.GenObject = CreateGenObject(d.Root, "TestData", "Two");
            a.SetString("Name", "Two");
            a.SetString("Display", display[1] == '1' ? "True" : "");
            a.SaveFields();
            a.GenObject = CreateGenObject(d.Root, "TestData", "Three");
            a.SetString("Name", "Three");
            a.SetString("Display", display[2] == '1' ? "True" : "");
            a.SaveFields();
            return(d);
        }
Example #3
0
        protected static GenDataBase SetUpLookupContextData()
        {
            var f        = new GenDataDef();
            var parentId = f.AddClass("", "Parent");

            f.AddClassInstanceProperty(parentId, "Name");
            var childId = f.AddClass("Parent", "Child");

            f.AddClassInstanceProperty(childId, "Name");
            f.AddClassInstanceProperty(childId, "Lookup");
            var lookupId = f.AddClass("Parent", "Lookup");

            f.AddClassInstanceProperty(lookupId, "Name");

            var a = new GenAttributes(f, 1);
            var d = new GenDataBase(f);
            var p = CreateGenObject(d.Root, "Parent", "Parent");

            a.GenObject = CreateGenObject(p, "Child", "Child1");
            a.SetString("Lookup", "Valid");
            a.SaveFields();

            a.GenObject = CreateGenObject(p, "Child", "Child2");
            a.SetString("Lookup", "Invalid");
            a.SaveFields();

            a.GenObject = CreateGenObject(p, "Lookup", "Valid");

            return(d);
        }
 /// <summary>
 /// Initializes a new instance of the GenObjectFieldViewModel class.
 /// </summary>
 /// <param name="genAttributes">The Generator Attributes object for the object owning this value.</param>
 /// <param name="propertyId">The ID of the property being edited.</param>
 /// <param name="property">The property definition of the field being edited.</param>
 /// <param name="isNew">Is this field in a new object?</param>
 /// <param name="isReadOnly">Is this field readonly?</param>
 public GenObjectFieldViewModel(GenAttributes genAttributes, int propertyId, Property property, bool isNew, bool isReadOnly)
 {
     IgnorePropertyValidation = true;
     GenAttributes            = genAttributes;
     _name = GenAttributes.Properties[propertyId];
     Name  = _name;
     if (property != null)
     {
         Name        = property.Name;
         Hint        = property.Title;
         DataType    = property.DataType;
         Default     = property.Default;
         ComboValues = SetComboValues(property.LookupType, property.LookupTable, property.LookupDependence);
         IsReadOnly  = isReadOnly;
         if (isNew)
         {
             GenAttributes.SetString(_name, Default); // Don't raise the Property Raised event
         }
     }
     else
     {
         Name        = _name;
         Hint        = "";
         DataType    = "String";
         Default     = "";
         ComboValues = null;
         IsReadOnly  = true;
         if (isNew)
         {
             GenAttributes.SetString(_name, Default); // Don't raise the Property Raised event
         }
     }
 }
        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"));
        }
Example #6
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);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the GenObjectViewModel class.
 /// </summary>
 /// <param name="genObject">The <see cref="GenObject"/> being edited.</param>
 /// <param name="definition">The class definition of the object being edited.</param>
 /// <param name="isReadOnly">Is this data readonly?</param>
 public GenObjectViewModel(GenObject genObject, GenNamedApplicationBase definition,
                           bool isReadOnly)
 {
     IsReadOnly = isReadOnly;
     IgnorePropertyValidation = true;
     Definition    = definition;
     GenAttributes = new GenAttributes(genObject.GenDataBase.GenDataDef, genObject.ClassId)
     {
         GenObject = genObject
     };
     GenObject = genObject;
     Changed   = false;
     IsNew     = false;
 }
Example #8
0
        protected static GenDataBase SetUpNumericComparisonData()
        {
            var f = GenDataDef.CreateMinimal();

            f.AddClassInstanceProperty(PropertyClassId, "Number");

            var d = new GenDataBase(f);
            var a = new GenAttributes(f, PropertyClassId);

            SetUpData(d);
            a.GenObject = GetFirstObjectOfSubClass(GetLastObjectInSubClass(GetFirstObject(d)), "Property");
            a.SetNumber("Number", 15);
            a.SaveFields();

            return(d);
        }
Example #9
0
        protected static GenDataBase PopulateInheritanceData(string dataName)
        {
            var f = SetUpVirtualDefinition().GenDataBase.AsDef();
            var d = new GenDataBase(f)
            {
                DataName = Path.GetFileNameWithoutExtension(dataName)
            };
            var container = CreateGenObject(d.Root, "Container", "Container");
            var virtual1  = CreateGenObject(container, "Virtual1", "V1Instance1");

            Assert.AreEqual(3, virtual1.ClassId);
            var @abstract = new GenAttributes(f, 3)
            {
                GenObject = virtual1
            };

            @abstract.SetString("V1Field", "Value 1");
            @abstract.SaveFields();
            CreateGenObject(virtual1, "Child", "V1I1Child1");
            CreateGenObject(virtual1, "Child", "V1I1Child2");
            var virtual2 = CreateGenObject(container, "Virtual2", "V2Instance1");

            Assert.AreEqual(4, virtual2.ClassId);
            @abstract.GenObject = virtual2;
            //@abstract.SetString("Name", "V2Instance1");
            @abstract.SetString("V2Field", "Value 1");
            @abstract.SaveFields();
            CreateGenObject(virtual2, "Child", "V2I1Child1");
            CreateGenObject(virtual2, "Child", "V2I1Child2");
            virtual1 = CreateGenObject(container, "Virtual1", "V1Instance2");
            Assert.AreEqual(3, virtual1.ClassId);
            @abstract.GenObject = virtual1;
            //@abstract.SetString("Name", "V1Instance2");
            @abstract.SetString("V1Field", "Value 2");
            @abstract.SaveFields();
            CreateGenObject(virtual1, "Child", "V1I2Child1");
            CreateGenObject(virtual1, "Child", "V1I2Child2");
            virtual2 = CreateGenObject(container, "Virtual2", "V2Instance2");
            Assert.AreEqual(4, virtual2.ClassId);
            @abstract.GenObject = virtual2;
            //@abstract.SetString("Name", "V2Instance2");
            @abstract.SetString("V2Field", "Value 2");
            @abstract.SaveFields();
            CreateGenObject(virtual2, "Child", "V2I2Child1");
            CreateGenObject(virtual2, "Child", "V2I2Child2");
            return(d);
        }
        public void IdentifierConditionProfileTest()
        {
            const string txt = "`[Class':" +
                               "`?Class.Name<Class.NameEQ:Class name is less than Class `]" +
                               "`?Class.Name=Class.NameEQ:Class name equals Class `]" +
                               "`?Class.Name>Class.NameEQ:Class name is greater than Class `]" +
                               "`?Class.Name<Class.NameLT:Class name is less than Clasa `]" +
                               "`?Class.Name=Class.NameLT:Class name equals Clasa `]" +
                               "`?Class.Name>Class.NameLT:Class name is greater than Clasa `]" +
                               "`?Class.Name<Class.NameGT:Class name is less than Clasz `]" +
                               "`?Class.Name=Class.NameGT:Class name equals Clasz `]" +
                               "`?Class.Name>Class.NameGT:Class name is greater than Clasz `]" +
                               "`]";
            var f = GenDataDef.CreateMinimal();

            f.AddClassInstanceProperty(ClassClassId, "NameLT");
            f.AddClassInstanceProperty(ClassClassId, "NameEQ");
            f.AddClassInstanceProperty(ClassClassId, "NameGT");
            f.AddClassInstanceProperty(ClassClassId, "NameBlank");

            var d = SetUpData(f);

            var c = GetFirstObject(d);

            Assert.AreEqual("Class", c.Attributes[0]);
            var a = new GenAttributes(f, ClassClassId)
            {
                GenObject = c
            };

            a.SetString("NameLT", "Clasa");
            a.SetString("NameEQ", "Class");
            a.SetString("NameGT", "Clasz");
            a.SetString("NameBlank", "");
            a.SaveFields();

            const string expectedExpansion = "Class name equals Class " +
                                             "Class name is greater than Clasa " +
                                             "Class name is less than Clasz ";
            var          expectedFragmentType = new[] { FragmentType.Segment };
            const string message = "Comparison conditions expected";

            ValidateExpansion(d, txt, expectedFragmentType, expectedExpansion, message);
        }
Example #11
0
        public void GenAttributePropertyTests()
        {
            var f       = new GenDataDef();
            var classId = f.AddClass("", "Class");

            f.AddClassInstanceProperty(classId, "Prop1");
            f.AddClassInstanceProperty(classId, "Prop2");
            var d = new GenDataBase(f);
            var o = CreateGenObject(d.Root, "Class");
            var a = new GenAttributes(f, 1)
            {
                GenObject = o
            };

            a.SetString("Prop1", "Prop1");
            a.SetString("Prop2", "Prop2");
            a.SaveFields();
            Assert.AreEqual(2, f.GetClassProperties(classId).Count);
        }
        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"));
        }
Example #13
0
        protected static GenDataBase SetUpParentOfVirtualData()
        {
            Assert.IsTrue(File.Exists(VirtualDefinitionFile));
            Assert.IsTrue(File.Exists(VirtualParentDefinitionFile));
            Assert.IsTrue(File.Exists(VirtualDataFile));
            var f = GenDataBase.DataLoader.LoadData(VirtualParentDefinitionFile).AsDef();
            var d = new GenDataBase(f)
            {
                DataName = "VirtualParentData"
            };
            var container = new GenAttributes(f, 1)
            {
                GenObject = CreateGenObject(d.Root, "Parent", "Parent")
            };

            container.SetString("Name", "Parent");
            container.SaveFields();
            GetFirstObject(d).SubClass[0].Reference = "TestData\\VirtualData";
            return(d);
        }
Example #14
0
        public void GenDataSaveTests()
        {
            const string fileName = "GenDataSaveTest.txt";
            const string expected = GenDataSaveText;

            var f = GenDataDef.CreateMinimal();

            f.AddClassInstanceProperty(ClassClassId, "Title");
            var a = new GenAttributes(f, ClassClassId);
            var d = new GenDataBase(f);

            SetUpData(d);
            a.GenObject = GetFirstObject(d);
            a.SetString("Title", "Class object");
            a.SaveFields();

            GenParameters.SaveToFile(d, fileName);

            var file = File.ReadAllText(fileName);

            Assert.AreEqual(expected, file);
        }
Example #15
0
        protected static GenDataBase SetUpComparisonData()
        {
            var f = GenDataDef.CreateMinimal();

            f.AddClassInstanceProperty(PropertyClassId, "NameLT");
            f.AddClassInstanceProperty(PropertyClassId, "NameEQ");
            f.AddClassInstanceProperty(PropertyClassId, "NameGT");
            f.AddClassInstanceProperty(PropertyClassId, "NameBlank");

            var d = new GenDataBase(f);

            SetUpData(d);

            var c = GetFirstObject(d);

            Assert.AreEqual("Class", c.Attributes[0]);
            var a = new GenAttributes(f, ClassClassId)
            {
                GenObject = c
            };

            a.SetString("NameLT", "Clasa");
            a.SetString("NameEQ", "Class");
            a.SetString("NameGT", "Clasz");
            a.SetString("NameBlank", "");
            a.SaveFields();

            c = GetLastObjectInSubClass(c);
            Assert.AreEqual("Property", c.Attributes[0]);
            a.GenObject = GetFirstObjectOfSubClass(c, "Property");
            a.SetString("NameLT", "Nama");
            a.SetString("NameEQ", "Name");
            a.SetString("NameGT", "Namz");
            a.SetString("NameBlank", "");
            a.SaveFields();

            return(d);
        }
Example #16
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));
            }
        }
 /// <summary>
 /// Cancels changes to the object data
 /// </summary>
 public override void Cancel()
 {
     GenAttributes.GetFields();
     base.Cancel();
 }
Example #18
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"));
        }
 /// <summary>
 /// Saves the object data
 /// </summary>
 public override void Save()
 {
     GenAttributes.SaveFields();
     base.Save();
 }