[Test] public void ByNameAndAttributesControlNS_NamePart() { PureElementNameComparisons(ElementSelectors .ByNameAndAttributesControlNS()); PureElementNameComparisons(ElementSelectors .ByNameAndAttributesControlNS(BAR)); }
[Test] public void ByNameAndAllAttributes() { XmlElement control = doc.CreateElement(FOO); control.SetAttribute(BAR, BAR); XmlElement equal = doc.CreateElement(FOO); equal.SetAttribute(BAR, BAR); XmlElement noAttributes = doc.CreateElement(FOO); XmlElement differentValue = doc.CreateElement(FOO); differentValue.SetAttribute(BAR, FOO); XmlElement differentName = doc.CreateElement(FOO); differentName.SetAttribute(FOO, FOO); XmlElement differentNS = doc.CreateElement(FOO); differentNS.SetAttribute(BAR, SOME_URI, BAR); Assert.IsTrue(ElementSelectors.ByNameAndAllAttributes(control, equal)); Assert.IsFalse(ElementSelectors.ByNameAndAllAttributes(control, noAttributes)); Assert.IsFalse(ElementSelectors.ByNameAndAllAttributes(noAttributes, control)); Assert.IsFalse(ElementSelectors.ByNameAndAllAttributes(control, differentValue)); Assert.IsFalse(ElementSelectors.ByNameAndAllAttributes(control, differentName)); Assert.IsFalse(ElementSelectors.ByNameAndAllAttributes(control, differentNS)); }
/// <inheritdoc cref="ElementSelector"/> public bool CanBeCompared(XmlElement controlElement, XmlElement testElement) { XmlElement currentControl = controlElement; XmlElement currentTest = testElement; // match on element names only for leading levels for (int currentLevel = 0; currentLevel <= levels - 2; currentLevel++) { if (!ElementSelectors.ByName(currentControl, currentTest) || !currentControl.HasChildNodes || !currentTest.HasChildNodes) { return(false); } XmlNode n1 = GetFirstEligibleChild(currentControl); XmlNode n2 = GetFirstEligibleChild(currentTest); if (n1 is XmlElement && n2 is XmlElement) { currentControl = n1 as XmlElement; currentTest = n2 as XmlElement; } else { return(false); } } // finally compare the level containing the text child node return(ElementSelectors.ByNameAndText(currentControl, currentTest)); }
public void ConditionalSelectorBuilderWontAllowMultipleDefaults() { Assert.Throws <InvalidOperationException>(() => { ElementSelectors.IConditionalSelectorBuilder b = ElementSelectors.ConditionalBuilder(); b.ElseUse(ElementSelectors.ByName); b.ElseUse(ElementSelectors.ByName); }); }
public void ConditionalSelectorBuilderWontAllowThenWithoutWhen() { Assert.Throws <InvalidOperationException>(() => { ElementSelectors.IConditionalSelectorBuilderThen t = (ElementSelectors.IConditionalSelectorBuilderThen)ElementSelectors.ConditionalBuilder(); t.ThenUse(ElementSelectors.ByName); }); }
public void ConditionalSelectorBuilderWontAllowMultipleWhensWithoutInterleavingThens() { Assert.Throws <InvalidOperationException>(() => { ElementSelectors.IConditionalSelectorBuilder b = ElementSelectors.ConditionalBuilder(); b.When(x => x != null); b.WhenElementIsNamed(new XmlQualifiedName("foo")); }); }
public void ConditionalReturnsFalseIfConditionIsNotMet() { XmlElement control = doc.CreateElement(FOO); XmlElement test = doc.CreateElement(FOO); Assert.IsFalse(ElementSelectors.ConditionalSelector(o => false, ElementSelectors.ByName) (control, test)); }
public void ConditionalSelectorBuilderWontAllowWhensWithoutThens() { Assert.Throws <InvalidOperationException>(() => { ElementSelectors.IConditionalSelectorBuilder b = ElementSelectors.ConditionalBuilder(); b.When(x => x != null); b.Build(); }); }
public void Not() { XmlElement control = doc.CreateElement(FOO); XmlElement equal = doc.CreateElement(FOO); XmlElement different = doc.CreateElement(BAR); Assert.IsFalse(ElementSelectors.Not(ElementSelectors.ByName) (control, equal)); Assert.IsTrue(ElementSelectors.Not(ElementSelectors.ByName) (control, different)); }
[Test] public void ByNameAndAttributes_NamePart() { PureElementNameComparisons(ElementSelectors .ByNameAndAttributes(new string[] {})); PureElementNameComparisons(ElementSelectors .ByNameAndAttributes(new XmlQualifiedName[] {})); PureElementNameComparisons(ElementSelectors.ByNameAndAttributes(BAR)); PureElementNameComparisons(ElementSelectors .ByNameAndAttributes(new XmlQualifiedName(BAR, SOME_URI))); }
public void Or() { XmlElement control = doc.CreateElement(FOO); XmlElement test = doc.CreateElement(BAR); Assert.IsFalse(ElementSelectors.Or(ElementSelectors.ByName) (control, test)); Assert.IsTrue(ElementSelectors.Or(ElementSelectors.ByName, ElementSelectors.Default) (control, test)); }
public void ConditionalAsksWrappedSelectorIfConditionIsMet() { XmlElement control = doc.CreateElement(FOO); XmlElement test = doc.CreateElement(BAR); XmlElement test2 = doc.CreateElement(FOO); Assert.IsFalse(ElementSelectors.ConditionalSelector(o => true, ElementSelectors.ByName) (control, test)); Assert.IsTrue(ElementSelectors.ConditionalSelector(o => true, ElementSelectors.ByName) (control, test2)); }
public void XPath() { string BAZ = "BAZ"; string XYZZY1 = "xyzzy1"; string XYZZY2 = "xyzzy2"; XmlElement control = doc.CreateElement(FOO); XmlElement bar = doc.CreateElement(BAR); control.AppendChild(bar); XmlElement baz = doc.CreateElement(BAZ); bar.AppendChild(baz); baz.AppendChild(doc.CreateTextNode(XYZZY1)); baz = doc.CreateElement(BAZ); bar.AppendChild(baz); baz.AppendChild(doc.CreateTextNode(XYZZY2)); XmlElement test = doc.CreateElement(FOO); bar = doc.CreateElement(BAR); test.AppendChild(bar); baz = doc.CreateElement(BAZ); bar.AppendChild(baz); baz.AppendChild(doc.CreateTextNode(XYZZY2)); baz = doc.CreateElement(BAZ); bar.AppendChild(baz); baz.AppendChild(doc.CreateTextNode(XYZZY1)); XmlElement test2 = doc.CreateElement(FOO); bar = doc.CreateElement(BAR); test2.AppendChild(bar); baz = doc.CreateElement(BAZ); bar.AppendChild(baz); baz.AppendChild(doc.CreateTextNode(XYZZY2)); baz = doc.CreateElement(BAZ); bar.AppendChild(baz); baz.AppendChild(doc.CreateTextNode(XYZZY2)); Assert.IsTrue(ElementSelectors.ByXPath(".//BAZ", ElementSelectors.ByNameAndText) (control, test)); Assert.IsFalse(ElementSelectors.ByXPath(".//BAZ", ElementSelectors.ByNameAndText) (control, test2)); Assert.IsTrue(ElementSelectors.ByXPath("./BAZ", ElementSelectors.ByNameAndText) (control.FirstChild as XmlElement, test.FirstChild as XmlElement)); }
public void Xor() { XmlElement control = doc.CreateElement(FOO); XmlElement test = doc.CreateElement(BAR); XmlElement test2 = doc.CreateElement(FOO); Assert.IsFalse(ElementSelectors.Xor(ElementSelectors.ByName, ElementSelectors.ByNameAndAllAttributes) (control, test)); Assert.IsTrue(ElementSelectors.Xor(ElementSelectors.ByName, ElementSelectors.Default) (control, test)); Assert.IsFalse(ElementSelectors.Xor(ElementSelectors.ByName, ElementSelectors.Default) (control, test2)); }
public void PlainStringNamed() { XmlElement control = doc.CreateElement(FOO); XmlElement controlNS = doc.CreateElement(FOO, SOME_URI); XmlElement test = doc.CreateElement(FOO); XmlElement testNS = doc.CreateElement(FOO, SOME_URI); Assert.IsFalse(ElementSelectors.SelectorForElementNamed(BAR, ElementSelectors.ByName) (control, test)); Assert.IsTrue(ElementSelectors.SelectorForElementNamed(FOO, ElementSelectors.ByName) (control, test)); Assert.IsTrue(ElementSelectors.SelectorForElementNamed(FOO, ElementSelectors.ByName) (controlNS, testNS)); }
public void And() { XmlElement control = doc.CreateElement(FOO); control.SetAttribute(BAR, SOME_URI, BAR); XmlElement test = doc.CreateElement(FOO); Assert.IsTrue(ElementSelectors.And(ElementSelectors.ByName) (control, test)); Assert.IsTrue(ElementSelectors.And(ElementSelectors.ByName, ElementSelectors.Default) (control, test)); Assert.IsFalse(ElementSelectors.And(ElementSelectors.ByName, ElementSelectors.Default, ElementSelectors.ByNameAndAllAttributes) (control, test)); }
public void QnameNamed() { XmlElement control = doc.CreateElement(FOO); XmlElement controlNS = doc.CreateElement(FOO, SOME_URI); XmlElement test = doc.CreateElement(FOO); XmlElement testNS = doc.CreateElement(FOO, SOME_URI); Assert.IsFalse(ElementSelectors.SelectorForElementNamed(new XmlQualifiedName(BAR), ElementSelectors.ByName) (control, test)); Assert.IsTrue(ElementSelectors.SelectorForElementNamed(new XmlQualifiedName(FOO), ElementSelectors.ByName) (control, test)); Assert.IsTrue(ElementSelectors.SelectorForElementNamed(new XmlQualifiedName(FOO, SOME_URI), ElementSelectors.ByName) (controlNS, testNS)); }
public void ConditionalBuilder() { XmlElement control = doc.CreateElement(FOO); XmlElement test = doc.CreateElement(BAR); ElementSelectors.IConditionalSelectorBuilder builder = ElementSelectors.ConditionalBuilder() .WhenElementIsNamed(FOO).ThenUse(ElementSelectors.ByName); Assert.IsFalse(builder.Build()(control, test)); builder.ElseUse(ElementSelectors.Default); // not or-ed Assert.IsFalse(builder.Build()(control, test)); XmlElement control2 = doc.CreateElement("baz"); Assert.IsTrue(builder.Build()(control2, test)); }
public void SelectorForElementNamedDoesntLikeNullNameXmlQualifiedNameVersion() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.SelectorForElementNamed((XmlQualifiedName)null, ElementSelectors.ByName)); }
public void SelectorForElementNamedDoesntLikeNullElementSelectorXmlQualifiedNameVersion() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.SelectorForElementNamed(new XmlQualifiedName("foo"), null)); }
public void SelectorForElementNamedDoesntLikeNullNameStringVersion() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.SelectorForElementNamed((string)null, ElementSelectors.ByName)); }
public void SelectorForElementNamedDoesntLikeNullElementSelectorStringVersion() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.SelectorForElementNamed("foo", null)); }
public void ConditionalSelectorDoesntLikeNullPredicate() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.ConditionalSelector(null, ElementSelectors.ByName)); }
public void ConditionalSelectorDoesntLikeNullElementSelector() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.ConditionalSelector(x => x != null, null)); }
public void XorDoesntLikeNullElementSelector2() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.Xor(ElementSelectors.ByName, null)); }
public void ByNameAndAttributesControlNSDoesntLikeNullName() { Assert.Throws <ArgumentException>(() => ElementSelectors.ByNameAndAttributesControlNS(new string[] { null })); }
public void NotDoesntLikeNullElementSelector() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.Not(null)); }
public void AndDoesntLikeNullElementSelector() { Assert.Throws <ArgumentException>(() => ElementSelectors.And(new ElementSelector[] { null })); }
public void ByNameAndAttributesDoesntLikeNullNameXmlQualifiedNameVersion() { Assert.Throws <ArgumentException>(() => ElementSelectors.ByNameAndAttributes(new XmlQualifiedName[] { null })); }
public void AndDoesntLikeNullElementSelectorList() { Assert.Throws <ArgumentNullException>(() => ElementSelectors.And((ElementSelector[])null)); }