public void TestDiff_fromByteArray_shouldSucceed()
        {
            // prepare testData
            byte[] controlXml = Encoding.UTF8.GetBytes("<a><b>Test Value</b></a>");

            // run test
            var myDiff = DiffBuilder.Compare(controlXml).WithTest(controlXml).Build();

            // validate result
            Assert.IsFalse(myDiff.HasDifferences(), "XML similar " + myDiff.ToString());
        }
        public void UsesCustomComparisonFormatter()
        {
            string control = "<a><b></b><c/></a>";
            string test    = "<a><b></b><c/><d/></a>";

            var myDiff = DiffBuilder.Compare(control).WithTest(test)
                         .WithComparisonController(ComparisonControllers.StopWhenDifferent)
                         .WithComparisonFormatter(new DummyComparisonFormatter())
                         .Build();

            Assert.AreEqual("foo", myDiff.ToString());
        }
        public void TestDiff_fromBuilder_shouldSucceed()
        {
            // prepare testData
            string controlXml = "<a><b>Test Value</b></a>";

            // run test
            var myDiff = DiffBuilder.Compare(Input.FromString(controlXml))
                         .WithTest(Input.FromString(controlXml))
                         .Build();

            // validate result
            Assert.IsFalse(myDiff.HasDifferences(), "XML similar " + myDiff.ToString());
        }
        public void TestDiff_withDifferenceEvaluator_shouldSucceed()
        {
            // prepare testData
            string control = "<a><b attr=\"abc\"></b></a>";
            string test    = "<a><b attr=\"xyz\"></b></a>";

            // run test
            var myDiff = DiffBuilder.Compare(control).WithTest(test)
                         .WithDifferenceEvaluator(IgnoreAttributeDifferenceEvaluator("attr"))
                         .Build();

            // validate result
            Assert.IsFalse(myDiff.HasDifferences(), myDiff.ToString());
        }
        public void TestDiff_withoutIgnoreComments_shouldFail()
        {
            // prepare testData
            string controlXml = "<a><b><!-- A comment -->Test Value</b></a>";
            string testXml    = "<a><b><!-- An other comment -->Test Value</b></a>";

            // run test
            var myDiff = DiffBuilder.Compare(Input.FromString(controlXml).Build())
                         .WithTest(Input.FromString(testXml).Build())
                         .Build();

            // validate result
            Assert.IsTrue(myDiff.HasDifferences(), myDiff.ToString());
        }
        public void TestDiff_withDefaultComparisonController_shouldReturnAllDifferences()
        {
            // prepare testData
            string control = "<a><b attr1=\"abc\" attr2=\"def\"></b></a>";
            string test    = "<a><b attr1=\"uvw\" attr2=\"xyz\"></b></a>";

            // run test
            var myDiff = DiffBuilder.Compare(control).WithTest(test)
                         .Build();

            // validate result
            Assert.IsTrue(myDiff.HasDifferences());
            Assert.That(myDiff.Differences.Count(), Is.EqualTo(2));
        }
        public void TestDiff_withoutNormalizeWhitespaces_shouldFail()
        {
            // prepare testData
            string controlXml = "<a><b>Test Value</b></a>";
            string testXml    = "<a>\n <b>\n  Test Value\n </b>\n</a>";

            // run test
            var myDiff = DiffBuilder.Compare(Input.FromString(controlXml).Build())
                         .WithTest(Input.FromString(testXml).Build())
                         .Build();

            // validate result
            Assert.IsTrue(myDiff.HasDifferences(), myDiff.ToString());
        }
Exemple #8
0
        public void TestDiff_withIgnoreElementContentWhitespaces_shouldSucceed()
        {
            // prepare testData
            string controlXml = "<a><b>Test Value</b></a>";
            string testXml    = "<a>\n <b>Test Value</b>\n</a>";

            // run test
            var myDiff = DiffBuilder.Compare(Input.FromString(controlXml).Build())
                         .WithTest(Input.FromString(testXml).Build())
                         .IgnoreElementContentWhitespace()
                         .Build();

            // validate result
            Assert.IsFalse(myDiff.HasDifferences(), "XML similar " + myDiff.ToString());
        }
        public void TestDiff_withCheckForSimilar_shouldSucceed()
        {
            // prepare testData
            string controlXml = "<a>Test Value</a>";
            string testXml    = "<a><![CDATA[Test Value]]></a>";

            // run test
            var myDiff = DiffBuilder.Compare(Input.FromString(controlXml).Build())
                         .WithTest(Input.FromString(testXml).Build())
                         .CheckForSimilar()
                         .Build();

            // validate result
            Assert.IsFalse(myDiff.HasDifferences(), "XML similar " + myDiff.ToString());
        }
Exemple #10
0
        public void TestDiff_withCheckForIdentical_shouldFail()
        {
            // prepare testData
            string controlXml = "<a>Test Value</a>";
            string testXml    = "<a><![CDATA[Test Value]]></a>";

            // run test
            var myDiff = DiffBuilder.Compare(Input.FromString(controlXml).Build())
                         .WithTest(Input.FromString(testXml).Build())
                         .CheckForIdentical()
                         .Build();

            // validate result
            Assert.IsTrue(myDiff.HasDifferences(), myDiff.ToString());
        }
Exemple #11
0
        public void TestDiff_withIgnoreCommentsUsingVersion_shouldSucceed(string xsltVersion)
        {
            // prepare testData
            string controlXml = "<a><b><!-- A comment -->Test Value</b></a>";
            string testXml    = "<a><b><!-- An other comment -->Test Value</b></a>";

            // run test
            var myDiff = DiffBuilder.Compare(Input.FromString(controlXml).Build())
                         .WithTest(Input.FromString(testXml).Build())
                         .IgnoreCommentsUsingXSLTVersion(xsltVersion)
                         .Build();

            // validate result
            Assert.IsFalse(myDiff.HasDifferences(), "XML similar " + myDiff.ToString());
        }
Exemple #12
0
        public void TestDiff_fromStream_shouldSucceed()
        {
            // prepare testData
            using (FileStream fs = new FileStream(TestResources.ANIMAL_FILE,
                                                  FileMode.Open,
                                                  FileAccess.Read)) {
                using (StreamReader r = new StreamReader(TestResources.ANIMAL_FILE)) {
                    // run test
                    var myDiff = DiffBuilder.Compare(fs).WithTest(r).Build();

                    // validate result
                    Assert.IsFalse(myDiff.HasDifferences(),
                                   "XML similar " + myDiff.ToString());
                }
            }
        }
Exemple #13
0
        public void TestDiff_withDifferenceEvaluator_shouldNotInterfereWithSimilar()
        {
            // prepare testData
            string control = "<a><b><![CDATA[abc]]></b></a>";
            string test    = "<a><b>abc</b></a>";

            // run test
            var myDiff = DiffBuilder.Compare(control).WithTest(test)
                         .WithDifferenceEvaluator(
                DifferenceEvaluators.Chain(DifferenceEvaluators.Default,
                                           IgnoreAttributeDifferenceEvaluator("attr")))
                         .CheckForSimilar()
                         .Build();

            // validate result
            Assert.IsFalse(myDiff.HasDifferences(), myDiff.ToString());
        }
Exemple #14
0
        public void TestDiff_withComparisonListener_shouldCallListener()
        {
            // prepare testData
            string             control            = "<a><b attr=\"abc\"></b></a>";
            string             test               = "<a><b attr=\"xyz\"></b></a>";
            List <Difference>  diffs              = new List <Difference>();
            ComparisonListener comparisonListener = (comparison, outcome) => {
                diffs.Add(new Difference(comparison, outcome));
            };

            // run test
            var myDiff = DiffBuilder.Compare(control).WithTest(test)
                         .WithComparisonListeners(comparisonListener)
                         .Build();

            // validate result
            Assert.IsTrue(myDiff.HasDifferences(), myDiff.ToString());
            Assert.That(diffs.Count, Is.GreaterThan(1));
        }
Exemple #15
0
        public void TestDiff_withCustomDifferenceEvaluator_shouldNotEvaluateSimilar()
        {
            // prepare testData
            string control = "<a><b><![CDATA[abc]]></b></a>";
            string test    = "<a><b>abc</b></a>";

            // run test
            var myDiff = DiffBuilder.Compare(control).WithTest(test)
                         .WithDifferenceEvaluator(IgnoreAttributeDifferenceEvaluator("attr"))
                         .CheckForSimilar()
                         .Build();

            // validate result
            Assert.IsTrue(myDiff.HasDifferences(), myDiff.ToString());
            IEnumerator <Difference> e = myDiff.Differences.GetEnumerator();

            Assert.IsTrue(e.MoveNext());
            Assert.That(e.Current.Result, Is.EqualTo(ComparisonResult.DIFFERENT));
        }
Exemple #16
0
        public void TestDiff_withExtraNodes()
        {
            // prepare testData
            string control = "<a><b></b><c/></a>";
            string test    = "<a><b></b><c/><d/></a>";

            // run test
            var myDiff = DiffBuilder.Compare(control).WithTest(test)
                         .WithComparisonController(ComparisonControllers.StopWhenDifferent)
                         .Build();

            // validate result
            Assert.IsTrue(myDiff.HasDifferences());
            Assert.That(myDiff.Differences.Count(), Is.EqualTo(1));

            // run test
            var myDiffWithFilter = DiffBuilder.Compare(control).WithTest(test)
                                   .WithNodeFilter(n => "d" != n.Name)
                                   .WithComparisonController(ComparisonControllers.StopWhenDifferent)
                                   .Build();

            // validate result
            Assert.IsFalse(myDiffWithFilter.HasDifferences());
        }
Exemple #17
0
        public void TestDiff_withAttributeDifferences()
        {
            // prepare testData
            string control = "<a><b attr1=\"abc\" attr2=\"def\"></b></a>";
            string test    = "<a><b attr1=\"uvw\" attr2=\"def\"></b></a>";

            // run test
            var myDiff = DiffBuilder.Compare(control).WithTest(test)
                         .WithComparisonController(ComparisonControllers.StopWhenDifferent)
                         .Build();

            // validate result
            Assert.IsTrue(myDiff.HasDifferences());
            Assert.That(myDiff.Differences.Count(), Is.EqualTo(1));

            // run test
            var myDiffWithFilter = DiffBuilder.Compare(control).WithTest(test)
                                   .WithAttributeFilter(a => "attr1" != a.Name)
                                   .WithComparisonController(ComparisonControllers.StopWhenDifferent)
                                   .Build();

            // validate result
            Assert.IsFalse(myDiffWithFilter.HasDifferences());
        }