public void RootedNavigator()
        {
            var source = new TestSource5();
            var nav = new NavigableNavigator(source, source.Get(1));

            // go to (/root) /1
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id);

            // go to (/root) /1/prop1
            Assert.IsTrue(nav.MoveToFirstChild());
            // go to (/root) /1/prop2
            Assert.IsTrue(nav.MoveToNext());
            // go to (/root) /1/3
            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(3, (nav.UnderlyingObject as TestContent).Id);

            // go to (/root) /1
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id);

            // go to (/root) ie root
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Root, nav.InternalState.Position);
            Assert.IsFalse(nav.MoveToParent());

            // can't go there
            Assert.IsFalse(nav.MoveToId("2"));
        }
        public void MoveToId()
        {
            var source = new TestSource5();
            var nav = new NavigableNavigator(source);

            // move to /root/1/3
            Assert.IsTrue(nav.MoveToId("3"));
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(3, (nav.UnderlyingObject as TestContent).Id);

            // move to /root/1
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id);

            // move to /root
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(-1, (nav.UnderlyingObject as TestContent).Id);

            // move up
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Root, nav.InternalState.Position);
            Assert.IsFalse(nav.MoveToParent());

            // move to /root/1
            Assert.IsTrue(nav.MoveToId("1"));
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id);

            // move to /root
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(-1, (nav.UnderlyingObject as TestContent).Id);

            // move up
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Root, nav.InternalState.Position);
            Assert.IsFalse(nav.MoveToParent());

            // move to /root
            Assert.IsTrue(nav.MoveToId("-1"));
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(-1, (nav.UnderlyingObject as TestContent).Id);

            // move up
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Root, nav.InternalState.Position);
            Assert.IsFalse(nav.MoveToParent());

            // get lost
            Assert.IsFalse(nav.MoveToId("666"));
        }
        public void NavigateMixed()
        {
            var source = new TestSource2();
            var nav = new NavigableNavigator(source);

            nav.MoveToRoot();
            nav.MoveToFirstChild();
            Assert.AreEqual("root", nav.Name);
            nav.MoveToFirstChild();
            Assert.AreEqual("type1", nav.Name); // our content
            nav.MoveToFirstChild();
            Assert.AreEqual("prop1", nav.Name); // our property
            Assert.AreEqual(XPathNodeType.Element, nav.NodeType);
            nav.MoveToFirstChild();

            // "<data><item1>poo</item1><item2 xx=\"33\" /><item2 xx=\"34\" /></data>"

            Assert.AreEqual(XPathNodeType.Element, nav.NodeType);
            Assert.AreEqual("data", nav.Name);

            nav.MoveToFirstChild();
            Assert.AreEqual(XPathNodeType.Element, nav.NodeType);
            Assert.AreEqual("item1", nav.Name);

            nav.MoveToNext();
            Assert.AreEqual(XPathNodeType.Element, nav.NodeType);
            Assert.AreEqual("item2", nav.Name);

            nav.MoveToParent();
            Assert.AreEqual(XPathNodeType.Element, nav.NodeType);
            Assert.AreEqual("data", nav.Name);

            nav.MoveToParent();
            Assert.AreEqual(XPathNodeType.Element, nav.NodeType);
            Assert.AreEqual("prop1", nav.Name);
        }
        public void CloneIsSafe()
        {
            var source = new TestSource5();
            var nav = new NavigableNavigator(source);
            TestContent content;

            Assert.AreEqual(NavigableNavigator.StatePosition.Root, nav.InternalState.Position);
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual("root", nav.Name); // at -1
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id);
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(NavigableNavigator.StatePosition.PropertyElement, nav.InternalState.Position);
            Assert.AreEqual("prop1", nav.Name);
            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual(NavigableNavigator.StatePosition.PropertyElement, nav.InternalState.Position);
            Assert.AreEqual("prop2", nav.Name);
            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(3, (nav.UnderlyingObject as TestContent).Id);

            // at that point nav is at /root/1/3

            var clone = nav.Clone() as NavigableNavigator;

            // move nav to /root/1/5 and ensure that clone stays at /root/1/3
            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(5, (nav.UnderlyingObject as TestContent).Id);
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, clone.InternalState.Position);
            Assert.AreEqual(3, (clone.UnderlyingObject as TestContent).Id);

            // move nav to /root/2
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id);
            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position);
            Assert.AreEqual(2, (nav.UnderlyingObject as TestContent).Id);
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(NavigableNavigator.StatePosition.PropertyElement, nav.InternalState.Position);
            Assert.AreEqual("prop1", nav.Name);
            Assert.AreEqual("p21", nav.Value);

            // move clone to .. /root/1
            Assert.IsTrue(clone.MoveToParent());

            // clone has not been corrupted by nav
            Assert.AreEqual(NavigableNavigator.StatePosition.Element, clone.InternalState.Position);
            Assert.AreEqual(1, (clone.UnderlyingObject as TestContent).Id);
        }
        public void Navigate()
        {
            var source = new TestSource1();
            var nav = new NavigableNavigator(source);

            nav.MoveToRoot();
            Assert.AreEqual("", nav.Name); // because we're at root
            nav.MoveToFirstChild();
            Assert.AreEqual("root", nav.Name);
            nav.MoveToFirstChild();
            Assert.AreEqual("type1", nav.Name); // our first content
            nav.MoveToFirstAttribute();
            Assert.AreEqual("id", nav.Name);
            Assert.AreEqual("1", nav.Value);
            nav.MoveToNextAttribute();
            Assert.AreEqual("prop1", nav.Name);
            Assert.AreEqual("1:p1", nav.Value);
            nav.MoveToNextAttribute();
            Assert.AreEqual("prop2", nav.Name);
            Assert.AreEqual("1:p2", nav.Value);
            Assert.IsFalse(nav.MoveToNextAttribute());
            nav.MoveToParent();
            nav.MoveToFirstChild();
            Assert.AreEqual("prop3", nav.Name);
            Assert.AreEqual("1:p3", nav.Value);

            Assert.IsFalse(nav.MoveToNext());
        }