示例#1
0
        public void Constuctor_WithNode_Should()
        {
            var node = GetTagNode();
            var tree = new NodeTree(node);

            Assert.AreEqual(node, tree.Root);
            Assert.AreEqual(node, tree.Current);
        }
示例#2
0
        public void FirstChild_WithNodeWithoutChildren_ShouldReturnFalseAndNotMoveCurrent()
        {
            var node = GetTagNode();
            var tree = new NodeTree(node);
            var result = tree.FirstChild();

            Assert.IsFalse(result);
            Assert.AreEqual(node, tree.Current);
        }
示例#3
0
        public void LastChild_WithNodeWithChildren_ShouldReturnTrueAndMoveCurrentToCurrentsLastChild()
        {
            var first = GetTagNode();
            var last = GetTagNode();
            var node = GetTagNodeWithChildren(first, last);
            var tree = new NodeTree(node);
            var result = tree.LastChild();

            Assert.IsTrue(result);
            Assert.AreEqual(last, tree.Current);
        }
示例#4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="selector"></param>
        /// <param name="builder"></param>
        public HtmlBuilder(string selector, IHtmlTreeBuilder builder)
        {
            _builder = builder;
            _selector = selector;

            if (string.IsNullOrEmpty(selector))
            {
                throw new ArgumentException("A selector is required to seed the node tree.");
            }

            _nodeTree = _builder.Build(_selector);
        }
示例#5
0
        public void Next_WithNodeThatHasNextSibling_ShouldReturnTrueAndMoveCurrentToCurrentsNextSibling()
        {
            var next = GetTagNode();
            var node = GetTagNodeWithNextSibling(next);
            var tree = new NodeTree(node);
            var result = tree.Next();

            Assert.IsTrue(result);
            Assert.AreEqual(next, tree.Current);
        }
示例#6
0
 public void Constuctor_WithNullNode_ShouldThrowArgumentNullException()
 {
     Node node = null;
     var tree = new NodeTree(node);
 }
示例#7
0
 public void Constuctor_WithNullNodeList_ShouldThrowArgumentNullException()
 {
     var tree = new NodeTree(null);
 }
示例#8
0
        public void ToString_WithNodeWithSiblings_ShouldReturnANodeWithSiblings()
        {
            var next = GetTagNode();
            var node = GetTagNodeWithNextSibling(next);
            var tree = new NodeTree(node);

            Assert.AreEqual("<div></div><div></div>", tree.ToString());
        }
示例#9
0
        public void ToString_WithNodeWithoutChildrenOrSiblings_ShouldReturnASimpleNode()
        {
            var node = GetTagNode();
            var tree = new NodeTree(node);

            Assert.AreEqual("<div></div>", tree.ToString());
        }
示例#10
0
        public void ToString_WithNodeWithChildren_ShouldReturnANodeWithChildren()
        {
            var first = GetTagNode();
            var last = GetTagNode();
            var node = GetTagNodeWithChildren(first, last);
            var tree = new NodeTree(node);

            Assert.AreEqual("<div><div></div><div></div></div>", tree.ToString());
        }
示例#11
0
        public void Previous_WithNodeWithoutPreviousSibling_ShouldReturnFalseAndNotMoveCurrent()
        {
            var node = GetTagNode();
            var tree = new NodeTree(node);
            var result = tree.Previous();

            Assert.IsFalse(result);
            Assert.AreEqual(node, tree.Current);
        }
示例#12
0
        public void Previous_WithNodeThatHasPreviousSibling_ShouldReturnTrueAndMoveCurrentToCurrentsPreviousSibling()
        {
            var prev = GetTagNode();
            var node = GetTagNodeWithPrevSibling(prev);
            var tree = new NodeTree(node);
            var result = tree.Previous();

            Assert.IsTrue(result);
            Assert.AreEqual(prev, tree.Current);
        }
示例#13
0
        public void Parent_WithNodeWithParent_ShouldReturnTrueAndMoveCurrentToCurrentsParent()
        {
            var parent = GetTagNode();
            var node = GetTagNodeWithParent(parent);
            var tree = new NodeTree(node);
            var result = tree.Parent();

            Assert.IsTrue(result);
            Assert.AreEqual(parent, tree.Current);
        }