Beispiel #1
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));
        }
Beispiel #2
0
 public void OrDoesntLikeNullElementSelector()
 {
     Assert.Throws <ArgumentException>(() =>
                                       ElementSelectors.Or(new ElementSelector[] { null }));
 }
Beispiel #3
0
 public void OrDoesntLikeNullElementSelectorList()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ElementSelectors.Or((ElementSelector[])null));
 }
Beispiel #4
0
        public void ByNameAndTextRec_Multilevel()
        {
            XmlDocument control = new XmlDocument();
            {
                XmlElement root = control.CreateElement("root");
                control.AppendChild(root);

                XmlElement controlSub = control.CreateElement("sub");
                root.AppendChild(controlSub);
                XmlElement controlSubSubValue = control.CreateElement("value");
                controlSub.AppendChild(controlSubSubValue);
                controlSubSubValue.AppendChild(control.CreateTextNode("1"));
                controlSubSubValue = control.CreateElement("value");
                controlSub.AppendChild(controlSubSubValue);
                controlSubSubValue.AppendChild(control.CreateTextNode("2"));

                controlSub = control.CreateElement("sub");
                root.AppendChild(controlSub);
                controlSubSubValue = control.CreateElement("value");
                controlSub.AppendChild(controlSubSubValue);
                controlSubSubValue.AppendChild(control.CreateTextNode("3"));
                controlSubSubValue = control.CreateElement("value");
                controlSub.AppendChild(controlSubSubValue);
                controlSubSubValue.AppendChild(control.CreateTextNode("4"));
            }
            XmlDocument test = new XmlDocument();

            {
                XmlElement root = test.CreateElement("root");
                test.AppendChild(root);

                XmlElement testSub = test.CreateElement("sub");
                root.AppendChild(testSub);
                XmlElement testSubValue = test.CreateElement("value");
                testSub.AppendChild(testSubValue);
                testSubValue.AppendChild(test.CreateTextNode("1"));
                testSubValue = test.CreateElement("value");
                testSub.AppendChild(testSubValue);
                testSubValue.AppendChild(test.CreateTextNode("2"));

                testSub = test.CreateElement("sub");
                root.AppendChild(testSub);
                testSubValue = test.CreateElement("value");
                testSub.AppendChild(testSubValue);
                testSubValue.AppendChild(test.CreateTextNode("4"));
                testSubValue = test.CreateElement("value");
                testSub.AppendChild(testSubValue);
                testSubValue.AppendChild(test.CreateTextNode("3"));
            }

            Org.XmlUnit.Builder.DiffBuilder builder = Org.XmlUnit.Builder.DiffBuilder.Compare(control)
                                                      .WithTest(test).CheckForSimilar()
                                                      .WithNodeMatcher(new DefaultNodeMatcher(ElementSelectors.Or(ByNameAndTextRecSelector.CanBeCompared,
                                                                                                                  ElementSelectors.ByName)));
            Diff d = builder.Build();

            Assert.IsTrue(d.HasDifferences(), d.ToString(new DefaultComparisonFormatter()));

            builder = Org.XmlUnit.Builder.DiffBuilder.Compare(control)
                      .WithTest(test).CheckForSimilar()
                      .WithNodeMatcher(new DefaultNodeMatcher(ByNameAndTextRecSelector.CanBeCompared,
                                                              ElementSelectors.ByName));
            d = builder.Build();
            Assert.IsFalse(d.HasDifferences(), d.ToString(new DefaultComparisonFormatter()));
        }