示例#1
0
 public void CanBeCombinedWithFailingMatcher()
 {
     Assert.That(() =>
                 Assert.That("foo", Is.StringContaining("bar")
                             & CompareConstraint.IsSimilarTo("")),
                 Throws.TypeOf <AssertionException>());
 }
示例#2
0
 public void TestIsSimilarTo_withFileInput()
 {
     ExpectThrows("test1.xml", "test2.xml",
                  () => Assert.That(new StreamSource(TestResources.TESTS_DIR + "test1.xml"),
                                    CompareConstraint.IsSimilarTo(new StreamSource(TestResources.TESTS_DIR
                                                                                   + "test2.xml"))));
 }
示例#3
0
 public void CreatesAUsefulMessageWhenFailingCombinedWithNot()
 {
     ExpectThrows("not is similar to the control document", "<a><b></b><c/></a>",
                  () =>
                  Assert.That("<a><b></b><c/></a>",
                              !CompareConstraint.IsSimilarTo("<a><b></b><c/></a>")));
 }
示例#4
0
        public void CanBeCombinedWithPassingMatcher()
        {
            string xml = "<a><c/><b/></a>";

            Assert.That(xml, Is.StringContaining("c")
                        & CompareConstraint.IsSimilarTo("<a><b/><c/></a>")
                        .WithNodeMatcher(new DefaultNodeMatcher(ElementSelectors.ByName)));
        }
示例#5
0
        public void TestIsSimilarTo_withDifferenceEvaluator_shouldSucceed()
        {
            // prepare TestData
            string control = "<a><b attr=\"abc\"></b></a>";
            string test    = "<a><b attr=\"xyz\"></b></a>";

            // run Test
            Assert.That(test, CompareConstraint.IsSimilarTo(control)
                        .WithDifferenceEvaluator(IgnoreAttributeDifferenceEvaluator("attr")));
        }
示例#6
0
        public void TestIsSimilarTo_withComparisonFormatter_shouldFailWithCustomMessage()
        {
            string control = "<a><b attr=\"abc\"></b></a>";
            string test    = "<a><b attr=\"xyz\"></b></a>";

            ExpectThrows("DESCRIPTION", "DETAIL-abc",
                         () => Assert.That(test, CompareConstraint
                                           .IsSimilarTo(control)
                                           .WithComparisonFormatter(new DummyComparisonFormatter())));
        }
示例#7
0
        public void TestDiff_withExtraNodes()
        {
            string control = "<a><b></b><c/></a>";
            string test    = "<a><b></b><c/><d/></a>";

            ExpectThrows("Expected child nodelist length '2' but was '3'", "",
                         () => Assert.That(test,
                                           CompareConstraint.IsSimilarTo(control)));
            Assert.That(test,
                        CompareConstraint.IsSimilarTo(control)
                        .WithNodeFilter(n => "d" != n.Name));
        }
示例#8
0
        public void TestDiff_withAttributeDifferences()
        {
            string control = "<a><b attr1=\"abc\" attr2=\"def\"></b></a>";
            string test    = "<a><b attr1=\"xyz\" attr2=\"def\"></b></a>";

            ExpectThrows("Expected attribute value 'abc' but was 'xyz'", "",
                         () => Assert.That(test,
                                           CompareConstraint.IsSimilarTo(control)));
            Assert.That(test,
                        CompareConstraint.IsSimilarTo(control)
                        .WithAttributeFilter(a => "attr1" != a.Name));
        }
示例#9
0
        public void TestCompareConstraintWrapper_shouldWriteFailedTestInput()
        {
            string control = "<a><b attr=\"abc\"></b></a>";
            string test    = "<a><b attr=\"xyz\"></b></a>";

            string fileName = GetTestResultFolder() + "/testCompareConstraintWrapper.xml";

            GetTestResultFolder();
            ExpectThrows("Expected attribute value 'abc' but was 'xyz'", "",
                         () => Assert.That(test,
                                           TestCompareConstraintWrapper.IsSimilarTo(control)
                                           .WithTestFileName(fileName)));
            Assert.That(new StreamSource(fileName),
                        CompareConstraint.IsSimilarTo(test));
        }
示例#10
0
        public void TestIsSimilarTo_withDifferenceListener_shouldCollectChanges()
        {
            CounterComparisonListener comparisonListener = new CounterComparisonListener();
            string controlXml = "<a><b>Test Value</b><c>ABC</c></a>";
            string testXml    = "<a><b><![CDATA[Test Value]]></b><c>XYZ</c></a>";

            ExpectThrows("Expected text value 'ABC' but was 'XYZ'", "",
                         () => Assert.That(testXml, CompareConstraint
                                           .IsSimilarTo(controlXml)
                                           .WithDifferenceListeners(comparisonListener.Notify)));

            Assert.That(comparisonListener.Differents, Is.EqualTo(1));
            Assert.That(comparisonListener.Similars, Is.EqualTo(1));
            Assert.That(comparisonListener.Equal, Is.EqualTo(0));
        }
示例#11
0
 public void TestIsSimilarTo_WithErrorForElementOrder_FailsWithExpectedMessage()
 {
     Assert.That("<a><c/><b/></a>", CompareConstraint.IsSimilarTo("<a><b/><c/></a>")
                 .WithNodeMatcher(new DefaultNodeMatcher(ElementSelectors.ByNameAndText)));
 }
示例#12
0
 public static TestCompareConstraintWrapper IsSimilarTo(object control)
 {
     return(new TestCompareConstraintWrapper(CompareConstraint.IsSimilarTo(control)));
 }
示例#13
0
 public void CantSetComparisonController()
 {
     Assert.That(() => CompareConstraint.IsSimilarTo("<foo/>")
                 .WithComparisonController(null),
                 Throws.TypeOf <NotImplementedException>());
 }
示例#14
0
 public void TestIsSimilarTo_withSwappedElements_shouldSucceed()
 {
     Assert.That("<a><c/><b/></a>", CompareConstraint.IsSimilarTo("<a><b/><c/></a>")
                 .WithNodeMatcher(new DefaultNodeMatcher(ElementSelectors.ByNameAndText)));
 }