public void TestElementMethods() { //GetElement SimpleElement se = new SimpleElement(); Assert.IsNull(se.GetElement("child1")); IXmlElement child1 = se.AddElement("child1"); Assert.IsNotNull(se.GetElement("child1")); //FindElement Assert.IsNull(se.FindElement("/child2")); Assert.AreEqual(child1, se.FindElement("/child1")); //EnsureElement Assert.AreEqual(se.ElementList.Count, 1); Assert.IsNotNull(se.EnsureElement("/child2")); IXmlElement child2 = se.GetElement("child2"); Assert.IsTrue(child2.IsMutable); Assert.AreEqual(se.ElementList.Count, 2); //element is added //GetSafeElement Assert.AreEqual(se.ElementList.Count, 2); Assert.AreEqual(se, se.GetSafeElement("")); IXmlElement child3 = se.GetSafeElement("/child3"); Assert.IsNotNull(child3); Assert.IsFalse(child3.IsMutable); Assert.AreEqual(se.ElementList.Count, 2); //element is not added IXmlElement child4 = se.GetSafeElement("/child3/../child4"); Assert.IsNotNull(child4); Exception e = null; try { se.GetSafeElement(null); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentNullException), e); e = null; try { se.GetSafeElement(".."); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); }