Beispiel #1
0
        private IStalkNode NewMultiChildNode(XmlElement fragment)
        {
            MultiChildLogicalNode node;

            switch (fragment.Name)
            {
            case "and":
                node = new AndNode();
                break;

            case "or":
                node = new OrNode();
                break;

            case "x-of":
                var xofnode = new XOfStalkNode();
                var minAttr = fragment.Attributes["minimum"];
                if (minAttr != null)
                {
                    xofnode.Minimum = XmlConvert.ToInt32(minAttr.Value);
                }

                var maxAttr = fragment.Attributes["maximum"];
                if (maxAttr != null)
                {
                    xofnode.Maximum = XmlConvert.ToInt32(maxAttr.Value);
                }

                node = xofnode;
                break;

            default:
                throw new XmlException("Unknown element " + fragment.Name);
            }

            node.ChildNodes = new List <IStalkNode>();

            foreach (XmlNode fragmentChildNode in fragment.ChildNodes)
            {
                var elem = fragmentChildNode as XmlElement;
                if (elem == null)
                {
                    continue;
                }

                var n = this.NewFromXmlFragment(elem);
                node.ChildNodes.Add(n);
            }

            return(node);
        }
Beispiel #2
0
        private XmlElement XOfToXml(XmlDocument doc, XOfStalkNode node)
        {
            var elem = this.CreateElement(doc, node);

            if (node.Minimum.HasValue)
            {
                elem.SetAttribute("minimum", XmlConvert.ToString(node.Minimum.Value));
            }

            if (node.Maximum.HasValue)
            {
                elem.SetAttribute("maximum", XmlConvert.ToString(node.Maximum.Value));
            }

            foreach (var childNode in node.ChildNodes)
            {
                elem.AppendChild(this.ToXml(doc, childNode));
            }

            return(elem);
        }
        public void ShouldSerialiseBasicXOfCorrectly()
        {
            // arrange
            var node = new XOfStalkNode
            {
                ChildNodes = new List <IStalkNode>
                {
                    new TrueNode(),
                    new FalseNode()
                }
            };

            var doc = new XmlDocument();

            var snf = new StalkNodeFactory(this.phabExternalMock.Object);

            // act
            var result = snf.ToXml(doc, node);

            // assert
            Assert.AreEqual("<x-of><true /><false /></x-of>", result.OuterXml);
        }