コード例 #1
0
		public void TestIListProperties()
		{
			Product p1 = new Product("egg");
			Product p2 = new Product("Monty Python Flying Circus Box");
			p2.Categories.Add("Silly Stuff");

			Customer c1 = new Customer("Rodrigo", "Oliveira", new Address("Al. Ribeir�o Preto", 487));
			Customer c2 = new Customer("Marcia", "Longo", new Address("Al. Ribeir�o Preto", 487));

			Order o1 = new Order(c1);
			o1.Add(new OrderItem(p1, 10));
			o1.Add(new OrderItem(p2, 1));

			Order o2 = new Order(c2);
			o2.Add(new OrderItem(p1, 15));
			o2.Add(new OrderItem(p2, 1));

			Order[] orders = new Order[] { o1, o2 };
			XPathObjectNavigator navigator = new XPathObjectNavigator(orders, "Orders");			
			AssertEquals(2, navigator.Select("//Order").Count);
			AssertEquals(2, navigator.Select("Order").Count);
			AssertEquals(o1, navigator.SelectObject("Order[1]"));
			AssertEquals(o2, navigator.SelectObject("Order[2]"));

			AssertEquals(o1, navigator.SelectObject("//Order[Customer/FirstName='Rodrigo']"));
			AssertEquals(o2, navigator.SelectObject("//Order[Customer/LastName='Longo']"));

			XPathNodeIterator i = navigator.Select("//Product[Name='egg']");
			AssertEquals(2, i.Count);
			AssertEquals(true, i.MoveNext());
			AssertEquals(p1, ((XPathObjectNavigator)i.Current).Node);

			AssertEquals(o2.Items[0], navigator.SelectObject("//OrderItem[Quantity>10]"));
			AssertEquals(p2, navigator.SelectObject("//Product[Categories/String='Silly Stuff']"));
		}