public void Test() { Person p = new Person("Gil","Tom",29); Navigator root = new Navigator(p); Navigator nav = (Navigator) root.Clone(); AssertEqual(XPathNodeType.Root, nav.NodeType); AssertFalse(nav.MoveToNext()); // Only one root AssertEqual(XPathNodeType.Root, nav.NodeType); AssertTrue(nav.MoveToFirstChild()); // Now points to a Person AssertFalse(nav.MoveToFirstChild()); // Person has no child AssertEqual(XPathNodeType.Element, nav.NodeType); AssertEqual("Person", nav.LocalName); AssertEqual(typeof(Person).FullName, nav.Value); AssertSame(p, nav.RealObject); AssertEqual("Gil", nav.GetAttribute("Name", string.Empty)); AssertTrue(nav.MoveToAttribute("Name",string.Empty)); // Now points to the Name property AssertEqual(XPathNodeType.Attribute, nav.NodeType); AssertEqual("Name", nav.LocalName); AssertEqual("Gil", nav.Value); AssertTrue(nav.MoveToParent()); AssertEqual(XPathNodeType.Element, nav.NodeType); AssertTrue(nav.MoveToFirstAttribute()); AssertEqual("Age", nav.LocalName); AssertEqual("29", nav.Value); AssertTrue(nav.MoveToNextAttribute()); AssertEqual("FirstName", nav.LocalName); AssertEqual("Tom", nav.Value); }
public static void TestSuite() { TestSimpleRegex(); Navigator nav = new Navigator(AssemblyFactory.GetAssembly(typeof(AutoTest).Assembly.Location)); nav.MoveToRoot(); AssertEqual("/", nav.Name); nav.MoveToFirstChild(); AssertEqual("Assembly", nav.Name); nav.MoveToFirstAttribute(); AssertEqual("Name", nav.Name); AssertEqual("aspectdng", nav.Value); nav.MoveToNextAttribute(); AssertEqual("FullName", nav.Name); AssertFalse(nav.MoveToNextAttribute(), "only be 2 attributes on an assembly"); AssertFalse(nav.MoveToFirstChild(), "attributes don't have firstChild"); nav.MoveToParent(); // To assembly AssertEqual("Assembly", nav.Name); nav.MoveToFirstChild(); AssertEqual("Attribute", nav.Name); nav.MoveToNext(); AssertEqual("Attribute", nav.Name); while (nav.Name != "Type") nav.MoveToNext(); nav.MoveToNext(); // Second type AssertEqual(1, nav.ChildIndex); Navigator otherNav = (Navigator) nav.Clone(); AssertTrue(nav.MoveToFirstChild()); // Type children while (nav.Name != "Method") nav.MoveToNext(); // First Method nav.MoveToNext(); // Second Method AssertEqual(1, nav.ChildIndex); AssertTrue(nav.MoveToFirstChild()); // Method children nav.MoveToFirstAttribute(); AssertTrue(nav.MoveToParent()); // Back to method children AssertTrue(nav.MoveToParent()); // Back to Method AssertTrue(nav.MoveToParent()); // Back to Type otherNav.MoveToFirstChild(); otherNav.MoveToParent(); AssertTrue(nav.IsSamePosition(otherNav)); nav.MoveToRoot(); AssertEqual(1, nav.SelectList("/").Count); AssertEqual(1, nav.SelectList("/Assembly").Count); AssertFalse(nav.SelectList("//Type").Count == 0); AssertFalse(nav.SelectList("//Type[starts-with(@Name, 'A')]").Count == 0); AssertTrue(nav.SelectList("//Type/*/*/*").Count == 0); AssertTrue(nav.SelectList("//Type").Count > nav.SelectList("//Type[starts-with(@Name, 'A')]").Count); AssertTrue(nav.SelectList("//Type").Count > nav.SelectList("//Type[.//Attribute]").Count); AssertFalse(nav.SelectList("//Type[.//Attribute]").Count == 0); DateTime start = DateTime.Now; int nb = nav.SelectList("//*[name(following::*[1]) = 'Type']").Count; Console.WriteLine("Time elapsed : " + (DateTime.Now - start).Milliseconds); }