Example #1
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);
        }
        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"));
        }
Example #4
0
        public void GenDataDefTest()
        {
            const string rootProfile =
                "Definition=Root\r\n" +
                "Class=Root\r\n" +
                "Field=Id\r\n" +
                ".\r\n" +
                "`[Root:Root[`?Root.Id:Id`?Root.Id<>True:=`@StringOrName:`{`Root.Id``]`]`]`]]\r\n" +
                "`]";

            var d = new GenDataDef {
                DefinitionName = "Root"
            };
            var i = d.AddClass("", "Root");

            Assert.AreEqual(1, i);
            Assert.AreEqual(i, d.GetClassId("Root"));
            Assert.AreEqual(0, d.Classes[0].IndexOfSubClass("Root"));
            var j = d.AddClassInstanceProperty(i, "Id");

            Assert.AreEqual(j, d.GetClassProperties(i).IndexOf("Id"));
            Assert.AreEqual(rootProfile, GenDataDefProfile.CreateProfile(d));

            var id = d.GetId("Root.Id");

            Assert.AreEqual(i, id.ClassId);
            Assert.AreEqual(j, id.PropertyId);

            i = d.AddClass("Root", "Sub");
            Assert.AreEqual(2, i);
            Assert.AreEqual(i, d.GetClassId("Sub"));
            Assert.AreEqual(0, d.Classes[1].IndexOfSubClass("Sub"));
            Assert.AreEqual(1, d.GetClassParent(i).ClassId);
            j = d.AddClassInstanceProperty(i, "SubId");
            Assert.AreEqual(0, j);
            Assert.AreEqual(j, d.GetClassProperties(i).IndexOf("SubId"));

            id = d.GetId("Sub.SubId");
            Assert.AreEqual(i, id.ClassId);
            Assert.AreEqual(j, id.PropertyId);
        }
Example #5
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);
        }
Example #6
0
        private static GenDataDef ExtractDef(ScanReader reader)
        {
            var f         = new GenDataDef();
            var classId   = -1;
            var className = "";
            var token     = reader.ScanWhile(ScanReader.Identifier);

            while (token != "")
            {
                switch (token)
                {
                case "Definition":
                    reader.ScanWhile(ScanReader.WhiteSpace);
                    if (reader.CheckChar('='))
                    {
                        reader.SkipChar();
                    }
                    reader.ScanWhile(ScanReader.WhiteSpace);
                    f.DefinitionName = reader.ScanWhile(ScanReader.QualifiedIdentifier);
                    break;

                case "Class":
                    reader.ScanWhile(ScanReader.WhiteSpace);
                    if (reader.CheckChar('='))
                    {
                        reader.SkipChar();
                    }
                    reader.ScanWhile(ScanReader.WhiteSpace);
                    className = reader.ScanWhile(ScanReader.Identifier);
                    classId   = f.AddClass(className);
                    if (f.Classes.Count == 2)
                    {
                        f.AddSubClass("", className);
                    }
                    reader.ScanWhile(ScanReader.WhiteSpace);
                    if (reader.CheckChar('['))
                    {
                        do
                        {
                            reader.SkipChar();
                            reader.ScanWhile(ScanReader.WhiteSpace);
                            var inheritorClassName = reader.ScanWhile(ScanReader.Identifier);
                            f.AddInheritor(className, inheritorClassName);
                            reader.ScanWhile(ScanReader.WhiteSpace);
                        } while (reader.CheckChar(','));
                        Contract.Assert(reader.CheckChar(']'), "Definition Error for class " + className + ": ] expected");
                        reader.SkipChar();
                    }
                    break;

                case "Field":
                    reader.ScanWhile(ScanReader.WhiteSpace);
                    if (reader.CheckChar('='))
                    {
                        reader.SkipChar();
                    }
                    if (reader.CheckChar('{'))
                    {
                        do
                        {
                            reader.SkipChar();
                            reader.ScanWhile(ScanReader.WhiteSpace);
                            var field = reader.ScanWhile(ScanReader.Identifier);
                            f.AddClassInstanceProperty(classId, field);
                            reader.ScanWhile(ScanReader.WhiteSpace);
                        } while (reader.CheckChar(','));
                        Contract.Assert(reader.CheckChar('}'), "Definition Error for class " + className + " fields list: } expected");
                        reader.SkipChar();
                    }
                    else
                    {
                        reader.ScanWhile(ScanReader.WhiteSpace);
                        var field = reader.ScanWhile(ScanReader.Identifier);
                        f.AddClassInstanceProperty(classId, field);
                    }
                    break;

                case "SubClass":
                    reader.ScanWhile(ScanReader.WhiteSpace);
                    if (reader.CheckChar('='))
                    {
                        reader.SkipChar();
                    }
                    if (reader.CheckChar('{'))
                    {
                        while (!reader.CheckChar('}'))
                        {
                            reader.SkipChar();
                            ParseDefSubClass(reader, f, className);
                        }
                        reader.SkipChar();
                    }
                    else
                    {
                        ParseDefSubClass(reader, f, className);
                        reader.ScanWhile(ScanReader.WhiteSpace);
                    }
                    break;
                }
                reader.ScanWhile(ScanReader.WhiteSpace);
                token = reader.ScanWhile(ScanReader.Identifier);
            }
            return(f);
        }