Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
 public void Constuctor_WithNullNode_ShouldThrowArgumentNullException()
 {
     Node node = null;
     var tree = new NodeTree(node);
 }
Ejemplo n.º 7
0
 public void Constuctor_WithNullNodeList_ShouldThrowArgumentNullException()
 {
     var tree = new NodeTree(null);
 }
Ejemplo n.º 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());
        }
Ejemplo n.º 9
0
        public void ToString_WithNodeWithoutChildrenOrSiblings_ShouldReturnASimpleNode()
        {
            var node = GetTagNode();
            var tree = new NodeTree(node);

            Assert.AreEqual("<div></div>", tree.ToString());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }