Beispiel #1
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);
        }
Beispiel #2
0
        static void TestTreeSerialization()
        {
            TestDocument doc0 = DocNode.Create <TestDocument>();
            TestDocument doc1 = (TestDocument)SerializeDeserializeNode(doc0);

            PathUtils.CheckParentChildrenLink(doc1, null);
        }
Beispiel #3
0
        static void TestDocDocObjRef()
        {
            TestDocument document = DocNode.Create <TestDocument>();

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

            foreach (string name in names)
            {
                UnitTest.Test(name != "testRef");
            }
        }
Beispiel #4
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");
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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");
        }