public void NodeElementsBeforeSelf() { XElement parent = new XElement("parent"); XElement child1a = new XElement("child1", new XElement("nested")); XElement child1b = new XElement("child1", new XElement("nested")); XElement child2a = new XElement("child2", new XElement("nested")); XElement child2b = new XElement("child2", new XElement("nested")); XComment comment = new XComment("this is a comment"); // If no parent, should not be any elements before it. Assert.Empty(comment.ElementsBeforeSelf()); parent.Add(child1a); parent.Add(child1b); parent.Add(child2a); parent.Add(comment); parent.Add(child2b); Assert.Equal(new XElement[] { child1a, child1b, child2a }, comment.ElementsBeforeSelf()); Assert.Equal(comment.ElementsBeforeSelf("child1"), new XElement[] { child1a, child1b }); Assert.Equal(new XElement[] { child1a, child1b, child2a }, child2b.ElementsBeforeSelf()); Assert.Equal(new XElement[] { child2a }, child2b.ElementsBeforeSelf("child2")); }
/// <summary> /// Tests the ElementsBeforeSelf methods on Node. /// </summary> /// <param name="context"></param> /// <returns></returns> //[Variation(Desc = "NodeElementsBeforeSelf")] public void NodeElementsBeforeSelf() { XElement parent = new XElement("parent"); XElement child1a = new XElement("child1", new XElement("nested")); XElement child1b = new XElement("child1", new XElement("nested")); XElement child2a = new XElement("child2", new XElement("nested")); XElement child2b = new XElement("child2", new XElement("nested")); XComment comment = new XComment("this is a comment"); // If no parent, should not be any elements before it. Validate.Enumerator(comment.ElementsBeforeSelf(), new XElement[0]); parent.Add(child1a); parent.Add(child1b); parent.Add(child2a); parent.Add(comment); parent.Add(child2b); Validate.Enumerator( comment.ElementsBeforeSelf(), new XElement[] { child1a, child1b, child2a }); Validate.Enumerator( comment.ElementsBeforeSelf("child1"), new XElement[] { child1a, child1b }); Validate.Enumerator( child2b.ElementsBeforeSelf(), new XElement[] { child1a, child1b, child2a }); Validate.Enumerator( child2b.ElementsBeforeSelf("child2"), new XElement[] { child2a }); }