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);
        }
Example #2
0
        public void DataNavigationTest()
        {
            var f = new GenDataDef();

            f.AddSubClass("", "Parent");
            f.AddClassInstanceProperty(f.GetClassId("Parent"), "Name");
            f.AddSubClass("Parent", "Class", "Definition");

            var d = new GenData(f);

            CreateGenObject(d, d.Root, "Parent", "Minimal");
            ((SubClassReference)d.Context[1].GenObject.SubClass[0]).Reference = "Minimal";
            CreateGenObject(d, d.Root, "Parent", "Basic");
            ((SubClassReference)d.Context[1].GenObject.SubClass[0]).Reference = "Basic";
            CreateGenObject(d, d.Root, "Parent", "Definition");
            ((SubClassReference)d.Context[1].GenObject.SubClass[0]).Reference = "Definition";
            //d.Cache.Merge();

            //var minimal = d.Cache["definition", "Minimal"];
            //var basic = d.Cache["definition", "Basic"];
            //var newDefinition = d.Cache["definition", "Definition"];

            var d1 = d.DuplicateContext();

            Navigate(d1, 0);
            Navigate(d1, 0);
        }
Example #3
0
        protected static void SetUpChildDef(string parentClassName, string childClassName, GenDataDef def)
        {
            def.AddSubClass(parentClassName, childClassName);
            var childClassId = def.GetClassId(childClassName);

            def.AddClassInstanceProperty(childClassId, "Name");
        }
Example #4
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 #5
0
        protected static GenDataDef SetUpParentChildDef(string parentClassName, string childClassName)
        {
            var def = new GenDataDef {
                DefinitionName = parentClassName
            };

            def.AddSubClass("", parentClassName);
            def.AddClassInstanceProperty(1, "Name");
            SetUpChildDef(parentClassName, childClassName, def);
            return(def);
        }
Example #6
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 #7
0
        protected static GenDataDef SetUpParentChildReferenceDef(string parentClassName, string childClassName,
                                                                 string childDefName, GenDataDef defChild)
        {
            var def = new GenDataDef {
                DefinitionName = parentClassName
            };

            def.Cache.Internal(childDefName, defChild);
            def.AddSubClass("", parentClassName);
            def.AddClassInstanceProperty(1, "Name");
            def.AddSubClass(parentClassName, childClassName, childDefName);
            return(def);
        }
Example #8
0
        public void ConsecutiveDataLoadTest()
        {
            var f = new GenDataDef();

            f.AddSubClass("", "Parent");
            f.AddClassInstanceProperty(f.GetClassId("Parent"), "Name");
            f.AddSubClass("Parent", "Class", "Definition");

            var d       = new GenData(f);
            var minimal = LoadGenData("Minimal");

            minimal.Last(1);
            Assert.AreEqual("Property", minimal.Context[1].GenObject.Attributes[0]);
            Assert.AreEqual(1, minimal.Context[3].Count);
            var basic = LoadGenData("Basic");

            basic.Last(1);
            Assert.AreEqual("Property", basic.Context[1].GenObject.Attributes[0]);
            Assert.AreEqual(2, basic.Context[3].Count);
            var definition = LoadGenData("Definition");

            definition.Last(1);
            Assert.AreEqual("Property", definition.Context[1].GenObject.Attributes[0]);
            Assert.AreEqual(7, definition.Context[3].Count);
            Assert.AreSame(minimal, d.Cache.Internal("definition", "Minimal", minimal));
            Assert.AreSame(basic, d.Cache.Internal("definition", "Basic", basic));
            var newDefinition = d.Cache.Internal("definition", "Definition", definition);

            Assert.AreNotSame(definition, newDefinition);
            Assert.AreSame(minimal, d.Cache.Internal("definition", "Minimal", minimal));
            Assert.AreSame(basic, d.Cache.Internal("definition", "Basic", basic));
            Assert.AreSame(newDefinition, d.Cache.Internal("definition", "Definition", definition));
            Assert.AreSame(minimal, d.Cache["Minimal"]);
            Assert.AreSame(basic, d.Cache["Basic"]);
            Assert.AreSame(newDefinition, d.Cache["Definition"]);
            d.Cache.Merge();

            CreateGenObject(d, d.Root, "Parent", "Minimal");
            ((SubClassReference)d.Context[1].GenObject.SubClass[0]).Reference = "Minimal";
            CreateGenObject(d, d.Root, "Parent", "Basic");
            ((SubClassReference)d.Context[1].GenObject.SubClass[0]).Reference = "Basic";
            CreateGenObject(d, d.Root, "Parent", "Definition");
            ((SubClassReference)d.Context[1].GenObject.SubClass[0]).Reference = "Definition";

            d.First(1);
            Assert.AreEqual("Minimal", d.Context[2].Reference);
            Assert.AreSame(minimal.GenDataBase, d.Context[2].GenObject.GenDataBase);
            d.Last(2);
            Assert.AreEqual("Property", d.Context[2].GenObject.Attributes[0]);
            Assert.AreEqual(1, d.Context[4].Count);
            d.Next(1);
            Assert.AreEqual("Basic", d.Context[2].Reference);
            Assert.AreSame(basic.GenDataBase, d.Context[2].GenObject.GenDataBase);
            d.Last(2);
            Assert.AreEqual("Property", d.Context[2].GenObject.Attributes[0]);
            Assert.AreEqual(2, d.Context[4].Count);
            d.Next(1);
            Assert.AreEqual("Definition", d.Context[2].Reference);
            Assert.AreSame(newDefinition.GenDataBase, d.Context[2].GenObject.GenDataBase);
            d.Last(2);
            Assert.AreEqual("Property", d.Context[2].GenObject.Attributes[0]);
            Assert.AreEqual(7, d.Context[4].Count);
            d.First(0);
        }
Example #9
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);
        }