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

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