Ejemplo n.º 1
0
        static void TestTreeSerialization()
        {
            TestDocument doc0 = DocNode.Create <TestDocument>();
            TestDocument doc1 = (TestDocument)SerializeDeserializeNode(doc0);

            PathUtils.CheckParentChildrenLink(doc1, null);
        }
Ejemplo n.º 2
0
        static void TestPathBasics()
        {
            IDocLeaf doc = DocNode.Create <TestDocument>();

            string       pathToMyInt = "TestList.2";
            DocObj <int> myInt       = PathUtils.ChildByPath <DocObj <int> >(
                doc as IDocNode, pathToMyInt);

            UnitTest.Test(myInt.Value == 2);
            UnitTest.Test(PathUtils.PathByChild(myInt) == pathToMyInt);

            string        pathToMyBool = "TestBool";
            DocObj <bool> myBool       = PathUtils.ChildByPath <DocObj <bool> >(
                doc as IDocNode, pathToMyBool);

            UnitTest.Test(myBool.Value == true);
            UnitTest.Test(PathUtils.PathByChild(myBool) == pathToMyBool);

            string       pathToMyInt2 = "SubDoc.TestInt0";
            DocObj <int> myInt2       = PathUtils.ChildByPath <DocObj <int> >(
                doc as IDocNode, pathToMyInt2);

            UnitTest.Test(myInt2.Value == 2);
            UnitTest.Test(PathUtils.PathByChild(myInt2) == pathToMyInt2);
        }
Ejemplo n.º 3
0
            public static DocNode CreateNode(Type type)
            {
                DocNode t = (DocNode)type.GetConstructor(emptyTypes).Invoke(emptyObjects);

                t.ResolveChildrenLinks();
                return(t);
            }
Ejemplo n.º 4
0
        static void TestDocBaseResolveParent()
        {
            IDocNode parent = new DocNode();
            IDocLeaf child  = new DocBase();

            child.ResolveParentLink(parent, "child");

            UnitTest.Test(child.Parent == parent);
            UnitTest.Test(child.Name == "child");
        }
Ejemplo n.º 5
0
        static void TestDocDocObjRef()
        {
            TestDocument document = DocNode.Create <TestDocument>();

            string[] names = FieldUtils.NamesByType(document.GetType());

            foreach (string name in names)
            {
                UnitTest.Test(name != "testRef");
            }
        }
Ejemplo n.º 6
0
        static void TestDocPropertyUtils()
        {
            TestDocument document = DocNode.Create <TestDocument>();

            string[] names = PropertyUtils.NamesByType(document.GetType());

            UnitTest.Test(names.Length == 3);
            UnitTest.Test(names[0] == "TestList");
            UnitTest.Test(names[1] == "TestBool");
            UnitTest.Test(names[2] == "SubDoc");
        }
Ejemplo n.º 7
0
        static void TestDocListResolveChildrenLinks()
        {
            DocList <DocNode> parent = new DocList <DocNode>();

            parent.Add(DocNode.Create <TestDocNodeClassBase>());
            parent.Add(DocNode.Create <TestDocNodeClassBase>());
            parent.Add(DocNode.Create <TestDocNodeClassBase>());

            foreach (IDocLeaf doc in ((IDocNode)parent).Children())
            {
                UnitTest.Test(doc.Parent == parent);
            }
        }
Ejemplo n.º 8
0
        static void TestSubDocSerialization()
        {
            TestSubDoc doc0 = DocNode.Create <TestSubDoc>();

            doc0.TestInt0.Value = 777;
            doc0.TestInt1.Value = 888;

            TestSubDoc doc1 = (TestSubDoc)SerializeDeserializeNode(doc0);

            UnitTest.Test(doc0.TestInt0.Value == doc1.TestInt0.Value);
            UnitTest.Test(doc0.TestInt1.Value == doc1.TestInt1.Value);

            PathUtils.CheckParentChildrenLink(doc1, null);
        }
Ejemplo n.º 9
0
        private static DocNode SerializeDeserializeNode(DocNode obj0)
        {
            byte[] binary;
            using (MemoryStream stream = new MemoryStream())
            {
                XmlUtils.Save(obj0, stream);
                binary = stream.ToArray();
            }

            DocNode obj1 = DocNode.Create(obj0.GetType());

            using (MemoryStream stream = new MemoryStream(binary))
            {
                XmlUtils.Load(obj1, stream);
            }

            return(obj1);
        }
Ejemplo n.º 10
0
        static void TestDocNodeResolveChildrenLinks()
        {
            IDocNode t0 = DocNode.Create <TestDocNodeClassBase>();

            UnitTest.Test(t0.Children().Count() == 2);
            foreach (IDocLeaf doc in t0.Children())
            {
                UnitTest.Test(doc.Parent == t0);
            }

            IDocNode t1 = DocNode.Create <TestDocNodeClassDerived>();

            UnitTest.Test(t1.Children().Count() == 4);
            foreach (IDocLeaf doc in t1.Children())
            {
                UnitTest.Test(doc.Parent == t1);
            }
        }
Ejemplo n.º 11
0
        static void TestDocNodeChildrenNames()
        {
            IDocNode t0 = DocNode.Create <TestDocNodeClassBase>();

            IList <string> childrenNames0 = t0.ChildrenNames() as IList <string>;

            UnitTest.Test(childrenNames0.Count == 2);
            UnitTest.Test(childrenNames0[0] == "M0");
            UnitTest.Test(childrenNames0[1] == "M1");

            IDocNode t1 = DocNode.Create <TestDocNodeClassDerived>();

            IList <string> childrenNames1 = t1.ChildrenNames() as IList <string>;

            UnitTest.Test(childrenNames1.Count == 4);
            UnitTest.Test(childrenNames1[0] == "M2");
            UnitTest.Test(childrenNames1[1] == "M3");
            UnitTest.Test(childrenNames1[2] == "M0");
            UnitTest.Test(childrenNames1[3] == "M1");
        }
Ejemplo n.º 12
0
 public TestDocNodeClassDerived()
 {
     M2 = new DocNode();
     M3 = new DocNode();
 }
Ejemplo n.º 13
0
 public TestDocNodeClassBase()
 {
     M0 = new DocNode();
     M1 = new DocNode();
 }