public void TestBuildThrowsInvalidOperationExceptionWhenAParentElementChildIsNull() { const string value = "Value_"; const string xmlTag = "name_"; NUnitFilterContainerElementForTest root = new NUnitFilterContainerElementForTest(null, NUnitElementType.RootFilter); XmlSerializableElementForTest leafChild = new XmlSerializableElementForTest(xmlTag + 1, value + 1, NUnitElementType.Test); leafChild.Parent = root; Assert.AreSame(root, leafChild.Parent); Assert.IsNull(root.Child); const string parentString = "{NUnitFilterContainerElementForTest: {Type: RootFilter, Parent: Null, Child: Null}}"; Assert.Throws( Is.TypeOf <InvalidOperationException>().And.Message .EqualTo($"The parent element's {parentString} child was null." + " Forward traversal will not proceed properly." + " This may indicate an error in the construction or parsing of the filter."), () => NUnitFilter.Build(leafChild)); }
public void TestToXmlStringWithParentNullAndElementTypeNotNotReturnsChildXmlString( [Values] bool withXmlTag) { // Create expected string of xml nodes const string valueChild = "Value_1"; const string xmlTagChild = "name_1"; XmlSerializableElementForTest child = new XmlSerializableElementForTest(xmlTagChild, valueChild, NUnitElementType.Test); string expectedValueChild = NUnitFilterTestHelper.CreateXmlNode(xmlTagChild, valueChild); // With tag includes parent xml tag, without is just value string expected = withXmlTag ? NUnitFilterTestHelper.CreateXmlNode(NUnitFilterTestHelper.XmlFilterTag, expectedValueChild) : expectedValueChild; NUnitFilterContainerElementForTest element = new NUnitFilterContainerElementForTest(null, NUnitElementType.RootFilter); element.SetChild(child); string actual = element.ToXmlString(withXmlTag); Assert.AreEqual(expected, actual); }