示例#1
0
        public void NestedNodesAndValues()
        {
            Layout layout = new Layout("Test Layout", "/Library", new List <LayoutNode>());

            LayoutNode layoutRoot = new LayoutNode("Library Root", "/Library", true, null,
                                                   new List <LayoutNode>(), new List <LayoutValue>(), new List <LayoutDataTable>());
            LayoutNode disksLayoutNode = new LayoutNode("My Disks", "Disks", true, null,
                                                        new List <LayoutNode>(), new List <LayoutValue>(), new List <LayoutDataTable>());
            LayoutNode cdLayoutNode = new LayoutNode("CD", "CD", true, null,
                                                     new List <LayoutNode>(), new List <LayoutValue>(), new List <LayoutDataTable>());

            LayoutValue artistLayoutValue = new LayoutValue("The Artist", "Artist");

            layout.Nodes.Add(layoutRoot);
            layoutRoot.ChildNodes.Add(disksLayoutNode);
            disksLayoutNode.ChildNodes.Add(cdLayoutNode);
            cdLayoutNode.Values.Add(artistLayoutValue);

            ModelParser parser = new ModelParser(layout);
            XmlModel    model  = parser.parseXmlString(XML_INPUT);

            // Validate root level node
            Assert.AreEqual(1, model.Nodes.Count, "Checking root level node");
            XmlModelNode libraryRoot = model.Nodes[0];

            Assert.AreEqual("Library Root", libraryRoot.Description);

            // Second level node
            Assert.AreEqual(1, libraryRoot.ChildNodes.Count, "Checking second level node");
            XmlModelNode disksLevel = libraryRoot.ChildNodes[0];

            Assert.AreEqual("My Disks", disksLevel.Description);

            // Third level node (two instances of CD)
            Assert.AreEqual(2, disksLevel.ChildNodes.Count);
            XmlModelNode cd1 = disksLevel.ChildNodes[0];
            XmlModelNode cd2 = disksLevel.ChildNodes[1];

            Assert.AreEqual("CD", cd1.Description);
            Assert.AreEqual("CD", cd2.Description);

            // Values under the third level node
            Assert.AreEqual(1, cd1.Values.Count);
            Assert.AreEqual("The Artist", cd1.Values[0].Description);
            Assert.AreEqual("Michael Jackson", cd1.Values[0].Value);

            Assert.AreEqual(1, cd2.Values.Count);
            Assert.AreEqual("The Artist", cd2.Values[0].Description);
            Assert.AreEqual("Nirvana", cd2.Values[0].Value);
        }
示例#2
0
        public void NonExistentNode_Required()
        {
            Layout layout = new Layout("Test Layout", "/Library", new List <LayoutNode>());

            LayoutNode node = new LayoutNode("NonexistentField", "/This/Path/Is/Fake", true, null,
                                             new List <LayoutNode>(), new List <LayoutValue>(), new List <LayoutDataTable>());
            LayoutValue someValue = new LayoutValue("Some Value", "@does_not_exist_as_well");

            node.Values.Add(someValue);

            layout.Nodes.Add(node);

            ModelParser parser = new ModelParser(layout);
            XmlModel    model  = parser.parseXmlString(XML_INPUT);

            // If the field is required, it comes to the output with an error status
            Assert.AreEqual("NonexistentField", model.Nodes[0].Description);
            Assert.AreEqual(true, model.Nodes[0].IsError);

            // The value is not inserted
            Assert.IsNull(model.Nodes[0].ChildNodes);
            Assert.IsNull(model.Nodes[0].DataTables);
            Assert.IsNull(model.Nodes[0].Values);
        }