public void Navigate()
    {
        var source = new TestSource1();
        var nav    = new NavigableNavigator(source);

        nav.MoveToRoot();
        Assert.AreEqual(string.Empty, 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());
    }
    public void QueryWithVariables()
    {
        var source = new TestSource1();
        var nav    = new NavigableNavigator(source);

        var iterator = nav.Select("//* [@prop1=$var]", new XPathVariable("var", "1:p1"));

        Assert.AreEqual(1, iterator.Count);
        iterator.MoveNext();
        Assert.AreEqual("type1", iterator.Current.Name);
    }
    public void OuterXml()
    {
        var source = new TestSource1();
        var nav    = new NavigableNavigator(source);

        const string xml = @"<root id=""-1"" prop1="""" prop2="""">
  <type1 id=""1"" prop1=""1:p1"" prop2=""1:p2"">
    <prop3>1:p3</prop3>
  </type1>
</root>";

        Assert.AreEqual(xml.Lf(), nav.OuterXml.Lf());
    }
    public void Query()
    {
        var source = new TestSource1();
        var nav    = new NavigableNavigator(source);

        var iterator = nav.Select("//type1");

        Assert.AreEqual(1, iterator.Count);
        iterator.MoveNext();
        Assert.AreEqual("type1", iterator.Current.Name);

        iterator = nav.Select("//* [@prop1='1:p1']");
        Assert.AreEqual(1, iterator.Count);
        iterator.MoveNext();
        Assert.AreEqual("type1", iterator.Current.Name);
    }
    public void XmlNodeList()
    {
        var source = new TestSource1();
        var nav    = new NavigableNavigator(source);

        var iterator = nav.Select("/*");

        // but, that requires that the underlying navigator implements IHasXmlNode
        // so it is possible to obtain nodes from the navigator - not possible yet
        var nodes = XmlNodeListFactory.CreateNodeList(iterator);

        Assert.AreEqual(nodes.Count, 1);
        var node = nodes[0];

        Assert.AreEqual(3, node.Attributes.Count);
        Assert.AreEqual("1", node.Attributes["id"].Value);
        Assert.AreEqual("1:p1", node.Attributes["prop1"].Value);
        Assert.AreEqual("1:p2", node.Attributes["prop2"].Value);
        Assert.AreEqual(1, node.ChildNodes.Count);
        Assert.AreEqual("prop3", node.FirstChild.Name);
        Assert.AreEqual("1:p3", node.FirstChild.Value);
    }