Example #1
0
 [Test] public void ByNameAndAttributesControlNS_NamePart()
 {
     PureElementNameComparisons(ElementSelectors
                                .ByNameAndAttributesControlNS());
     PureElementNameComparisons(ElementSelectors
                                .ByNameAndAttributesControlNS(BAR));
 }
Example #2
0
        [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));
        }
Example #3
0
        /// <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));
        }
Example #4
0
 public void ConditionalSelectorBuilderWontAllowMultipleDefaults()
 {
     Assert.Throws <InvalidOperationException>(() => {
         ElementSelectors.IConditionalSelectorBuilder b = ElementSelectors.ConditionalBuilder();
         b.ElseUse(ElementSelectors.ByName);
         b.ElseUse(ElementSelectors.ByName);
     });
 }
Example #5
0
 public void ConditionalSelectorBuilderWontAllowThenWithoutWhen()
 {
     Assert.Throws <InvalidOperationException>(() => {
         ElementSelectors.IConditionalSelectorBuilderThen t =
             (ElementSelectors.IConditionalSelectorBuilderThen)ElementSelectors.ConditionalBuilder();
         t.ThenUse(ElementSelectors.ByName);
     });
 }
Example #6
0
 public void ConditionalSelectorBuilderWontAllowMultipleWhensWithoutInterleavingThens()
 {
     Assert.Throws <InvalidOperationException>(() => {
         ElementSelectors.IConditionalSelectorBuilder b =
             ElementSelectors.ConditionalBuilder();
         b.When(x => x != null);
         b.WhenElementIsNamed(new XmlQualifiedName("foo"));
     });
 }
Example #7
0
        public void ConditionalReturnsFalseIfConditionIsNotMet()
        {
            XmlElement control = doc.CreateElement(FOO);
            XmlElement test    = doc.CreateElement(FOO);

            Assert.IsFalse(ElementSelectors.ConditionalSelector(o => false,
                                                                ElementSelectors.ByName)
                               (control, test));
        }
Example #8
0
 public void ConditionalSelectorBuilderWontAllowWhensWithoutThens()
 {
     Assert.Throws <InvalidOperationException>(() => {
         ElementSelectors.IConditionalSelectorBuilder b =
             ElementSelectors.ConditionalBuilder();
         b.When(x => x != null);
         b.Build();
     });
 }
Example #9
0
        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));
        }
Example #10
0
 [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)));
 }
Example #11
0
        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));
        }
Example #12
0
        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));
        }
Example #13
0
        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));
        }
Example #14
0
        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));
        }
Example #15
0
        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));
        }
Example #16
0
        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));
        }
Example #17
0
        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));
        }
Example #18
0
        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));
        }
Example #19
0
 public void SelectorForElementNamedDoesntLikeNullNameXmlQualifiedNameVersion()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.SelectorForElementNamed((XmlQualifiedName)null, ElementSelectors.ByName));
 }
Example #20
0
 public void SelectorForElementNamedDoesntLikeNullElementSelectorXmlQualifiedNameVersion()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.SelectorForElementNamed(new XmlQualifiedName("foo"), null));
 }
Example #21
0
 public void SelectorForElementNamedDoesntLikeNullNameStringVersion()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.SelectorForElementNamed((string)null, ElementSelectors.ByName));
 }
Example #22
0
 public void SelectorForElementNamedDoesntLikeNullElementSelectorStringVersion()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.SelectorForElementNamed("foo", null));
 }
Example #23
0
 public void ConditionalSelectorDoesntLikeNullPredicate()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.ConditionalSelector(null, ElementSelectors.ByName));
 }
Example #24
0
 public void ConditionalSelectorDoesntLikeNullElementSelector()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.ConditionalSelector(x => x != null, null));
 }
Example #25
0
 public void XorDoesntLikeNullElementSelector2()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.Xor(ElementSelectors.ByName, null));
 }
Example #26
0
 public void ByNameAndAttributesControlNSDoesntLikeNullName()
 {
     Assert.Throws <ArgumentException>(() =>
                                       ElementSelectors.ByNameAndAttributesControlNS(new string[] { null }));
 }
Example #27
0
 public void NotDoesntLikeNullElementSelector()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.Not(null));
 }
Example #28
0
 public void AndDoesntLikeNullElementSelector()
 {
     Assert.Throws <ArgumentException>(() =>
                                       ElementSelectors.And(new ElementSelector[] { null }));
 }
Example #29
0
 public void ByNameAndAttributesDoesntLikeNullNameXmlQualifiedNameVersion()
 {
     Assert.Throws <ArgumentException>(() =>
                                       ElementSelectors.ByNameAndAttributes(new XmlQualifiedName[] { null }));
 }
Example #30
0
 public void AndDoesntLikeNullElementSelectorList()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.And((ElementSelector[])null));
 }