Exemple #1
2
 public void AssertStringEqualAndIdenticalToSelf()
 {
     string control = "<assert>true</assert>";
       string test = "<assert>true</assert>";
       var xmlDiff = new XmlDiff(control, test, diffConfiguration);
       AssertXml.AreIdentical(xmlDiff);
       AssertXml.AreEqual(xmlDiff);
 }
        public void CanConfigureNotToUseValidatingParser()
        {
            DiffConfiguration diffConfiguration = new DiffConfiguration(useValidatingParser: false);
              Assert.AreEqual(false, diffConfiguration.UseValidatingParser);
              System.Console.WriteLine("Use validating parser: " + diffConfiguration.UseValidatingParser.ToString());

              FileStream controlFileStream = File.Open(ValidatorTests.VALID_FILE,
                                               FileMode.Open, FileAccess.Read);
              FileStream testFileStream = File.Open(ValidatorTests.INVALID_FILE,
                                            FileMode.Open, FileAccess.Read);
              try
              {
            XmlDiff diff = new XmlDiff(new XmlInput(controlFileStream),
                                   new XmlInput(testFileStream),
                                   diffConfiguration);
            diff.Compare();
              }
              catch (XmlSchemaException e)
              {
            Assert.Fail("Unexpected validation failure: " + e.Message);
              }
              finally
              {
            controlFileStream.Close();
            testFileStream.Close();
              }
        }
 [Test] public void AssertDifferentStringsNotEqualNorIdentical() {
     string control = "<assert>true</assert>";
     string test = "<assert>false</assert>";
     XmlDiff xmlDiff = new XmlDiff(control, test);
     XmlAssertion.AssertXmlNotIdentical(xmlDiff);
     XmlAssertion.AssertXmlNotEquals(xmlDiff);
 }        
 public void CreateDiffResult()
 {
     _result = new DiffResult();
     _diff = new XmlDiff("<a/>", "<b/>");
     _majorDifference = new Difference(DifferenceType.ELEMENT_TAG_NAME_ID, XmlNodeType.Element, XmlNodeType.Element);
     _minorDifference = new Difference(DifferenceType.ATTR_SEQUENCE_ID, XmlNodeType.Comment, XmlNodeType.Comment);
 }
 private static void AssertXmlEquals(XmlDiff xmlDiff, bool equalOrNot) {
     DiffResult diffResult = xmlDiff.Compare();
     if (equalOrNot) {
       NUnit.Framework.Assert.IsTrue(diffResult.Equal, diffResult.StringValue);
     } else {
       NUnit.Framework.Assert.IsFalse(diffResult.Equal, diffResult.StringValue);
     }
 }
Exemple #6
0
 public void AssertDifferentStringsNotEqualNorIdentical()
 {
     string control = "<assert>true</assert>";
       string test = "<assert>false</assert>";
       XmlDiff xmlDiff = new XmlDiff(control, test, diffConfiguration);
       AssertXml.AreNotIdentical(xmlDiff);
       AssertXml.AreNotEqual(xmlDiff);
 }
 private static void AssertXmlIdentical(XmlDiff xmlDiff, bool identicalOrNot) {
     DiffResult diffResult = xmlDiff.Compare();
     if (identicalOrNot) {
       NUnit.Framework.Assert.IsTrue(diffResult.Identical, xmlDiff.OptionalDescription);
     } else {
       NUnit.Framework.Assert.IsFalse(diffResult.Identical, xmlDiff.OptionalDescription);
     }
 }
 public void AssertXmlIdenticalUsesOptionalDescription()
 {
     string description = "An Optional Description";
     try {
         XmlDiff diff = new XmlDiff(new XmlInput("<a/>"), new XmlInput("<b/>"),
                                    new DiffConfiguration(description));
         XmlAssertion.AssertXmlIdentical(diff);
     } catch (NUnit.Framework.AssertionException e) {
         Assertion.AssertEquals(true, e.Message.StartsWith(description));
     }
 }
 public void DifferenceFound(XmlDiff inDiff, Difference difference)
 {
     _identical = false;
     if (difference.MajorDifference) {
         _equal = false;
     }
     _difference = difference;
     if (_stringBuilder.Length == 0) {
         _stringBuilder.Append(inDiff.OptionalDescription);
     }
     _stringBuilder.Append(Environment.NewLine).Append(difference);
 }
 [Test] public void AssertXmlEqualsUsesOptionalDescription() {
     string description = "Another Optional Description";
     bool caughtException = true;
     try {
         XmlDiff diff = new XmlDiff(new XmlInput("<a/>"), new XmlInput("<b/>"), 
                                    new DiffConfiguration(description));
         XmlAssertion.AssertXmlEquals(diff);
         caughtException = false;
     } catch (NUnit.Framework.AssertionException e) {
         Assert.IsTrue(e.Message.IndexOf(description) > -1);
     }
     Assert.IsTrue(caughtException);
 }
Exemple #11
0
 public void AssertXmlIdenticalUsesOptionalDescription()
 {
     string description = "An Optional Description";
       bool caughtException = true;
       try
       {
     XmlDiff diff = new XmlDiff(new XmlInput("<a/>"), new XmlInput("<b/>"),
                            new DiffConfiguration(description, useValidatingParser: false));
     AssertXml.AreIdentical(diff);
     caughtException = false;
       }
       catch (NUnit.Framework.AssertionException e)
       {
     Assert.IsTrue(e.Message.IndexOf(description) > -1);
       }
       Assert.IsTrue(caughtException);
 }
 public void DefaultConfiguredToUseValidatingParser() {
     DiffConfiguration diffConfiguration = new DiffConfiguration();
     Assert.AreEqual(DiffConfiguration.DEFAULT_USE_VALIDATING_PARSER, 
                            diffConfiguration.UseValidatingParser);
     
     bool exception = false;
     using (FileStream controlFileStream = File.Open(ValidatorTests.VALID_FILE, 
                                                     FileMode.Open,
                                                     FileAccess.Read))
     using (FileStream testFileStream = File.Open(ValidatorTests.INVALID_FILE, 
                                                  FileMode.Open,
                                                  FileAccess.Read)) {
       try {
         XmlDiff diff = new XmlDiff(new StreamReader(controlFileStream), 
                                    new StreamReader(testFileStream));
         diff.Compare();
       } catch (System.Exception) {
         // should be an XmlSchemaValidationException in .NET 2.0
         // and later
         exception = true;
       }
     }
     Assert.IsTrue(exception, "expected validation to fail");
 }
 private void PerformAssertion(XmlDiff diff, bool assertion)
 {
     Assert.AreEqual(assertion, diff.Compare().Equal);
       Assert.AreEqual(assertion, diff.Compare().Identical);
 }
 private void PerformAssertion(string control, string test, bool assertion,
                           DiffConfiguration xmlUnitConfiguration)
 {
     XmlDiff diff = new XmlDiff(new XmlInput(control), new XmlInput(test),
                          xmlUnitConfiguration);
       PerformAssertion(diff, assertion);
 }
 private void PerformAssertion(string control, string test, bool assertion)
 {
     XmlDiff diff = new XmlDiff(control, test);
       PerformAssertion(diff, assertion);
 }
Exemple #16
0
 public static void AssertXmlIdentical(XmlDiff xmlDiff)
 {
     AssertXmlIdentical(xmlDiff, true);
 }
Exemple #17
0
 public static void AssertXmlEquals(XmlDiff xmlDiff)
 {
     AssertXmlEquals(xmlDiff, true);
 }
 private static void AssertXmlIdentical(XmlDiff xmlDiff, bool identicalOrNot)
 {
     DiffResult diffResult = xmlDiff.Compare();
     AssertEquals(xmlDiff.OptionalDescription, identicalOrNot, diffResult.Identical);
 }
Exemple #19
0
 public static void AreIdentical(XmlDiff xmlDiff, String message)
 {
     AreIdentical(xmlDiff, message, null);
 }
Exemple #20
0
 /// <summary>Assert that two pieces of XML markup are identical</summary>
 /// <param name="xmlDiff">The result of an XML comparison</param>
 /// <param name="message">The message that will be displayed on failure</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 public static void AreIdentical(XmlDiff xmlDiff, String message, Object[] args)
 {
     AreIdentical(xmlDiff, true, message, args);
 }
Exemple #21
0
        /// <summary>Worker method to determine whether two pieces of xml markup are identical</summary>
        /// <param name="xmlDiff">The result of an XML comparison</param>
        /// <param name="assertion">true if asserting that the result is identical</param>
        /// <param name="message">The message that will be displayed on failure</param>
        /// <param name="args">Arguments to be used in formatting the message</param>
        private static void AreIdentical(XmlDiff xmlDiff, Boolean assertion, String message, Object[] args)
        {
            var diffResult = xmlDiff.Compare();
              String msg = message;

              if (message.Equals(String.Empty))
              {
            msg = xmlDiff.OptionalDescription;
              }

              if (assertion)
              {
            NUnit.Framework.Assert.IsTrue(diffResult.Identical, msg, args);
              }
              else
              {
            NUnit.Framework.Assert.IsFalse(diffResult.Identical, msg, args);
              }
        }
Exemple #22
0
        /// <summary>Worker method to determine whether two pieces of xml markup are similar</summary>
        /// <param name="xmlDiff">The result of an XML comparison</param>
        /// <param name="assertion">true if asserting that the result is similar</param>
        /// <param name="message">The message that will be displayed on failure</param>
        /// <param name="args">Arguments to be used in formatting the message</param>
        private static void AreEqual(XmlDiff xmlDiff, Boolean assertion, String message = "", Object[] args = null)
        {
            var diffResult = xmlDiff.Compare();
              String msg = message;

              if (String.IsNullOrEmpty(message))
              {
            msg = diffResult.StringValue;
              }

              if (assertion)
              {
            NUnit.Framework.Assert.IsTrue(diffResult.Equal, msg, args);
              }
              else
              {
            NUnit.Framework.Assert.IsFalse(diffResult.Equal, msg, args);
              }
        }
        public void DefaultConfiguredToUseValidatingParser()
        {
            DiffConfiguration diffConfiguration = new DiffConfiguration();
              Assert.AreEqual(DiffConfiguration.DEFAULT_USE_VALIDATING_PARSER,
                             diffConfiguration.UseValidatingParser);

              using (FileStream controlFileStream = File.Open(ValidatorTests.VALID_FILE,
                                                      FileMode.Open,
                                                      FileAccess.Read))
              using (FileStream testFileStream = File.Open(ValidatorTests.INVALID_FILE,
                                                   FileMode.Open,
                                                   FileAccess.Read))
              {
            XmlDiff diff = new XmlDiff(new StreamReader(controlFileStream), new StreamReader(testFileStream));
            Assert.Throws<XmlSchemaValidationException>(delegate
            {
              diff.Compare();
            });
              }
        }
 public static void AssertXmlIdentical(XmlDiff xmlDiff)
 {
     AssertXmlIdentical(xmlDiff, true);
 }
Exemple #25
0
 public static void AreIdentical(XmlDiff xmlDiff)
 {
     AreIdentical(xmlDiff, String.Empty, null);
 }
Exemple #26
0
 public static void AssertXmlNotIdentical(XmlDiff xmlDiff)
 {
     AssertXmlIdentical(xmlDiff, false);
 }
 private static void AssertXmlEquals(XmlDiff xmlDiff, bool equalOrNot)
 {
     DiffResult diffResult = xmlDiff.Compare();
     Assertion.AssertEquals(diffResult.StringValue, equalOrNot, diffResult.Equal);
 }
 public static void AssertXmlNotIdentical(XmlDiff xmlDiff)
 {
     AssertXmlIdentical(xmlDiff, false);
 }
 public static void AssertXmlEquals(XmlDiff xmlDiff)
 {
     AssertXmlEquals(xmlDiff, true);
 }
 private DiffResult PerformDiff(TextReader reader1, TextReader reader2) {            
     _xmlDiff = new XmlDiff(reader1, reader2);
     DiffResult result = _xmlDiff.Compare();
     return result;
 }
 public static void AssertXmlNotEquals(XmlDiff xmlDiff)
 {
     AssertXmlEquals(xmlDiff, false);
 }
Exemple #32
0
 public static void AssertXmlNotEquals(XmlDiff xmlDiff)
 {
     AssertXmlEquals(xmlDiff, false);
 }
		private bool CompareXml(string expectedResult, string actualResult)
		{
			XmlDiff diff = new XmlDiff(expectedResult, actualResult);
			return diff.Compare().Equal;
		}
        private void CheckXmlMapping(string hbm,params string[] stream)
        {
            NameTable nt = new NameTable();
            nt.Add("urn:nhibernate-mapping-2.2");
            var nsmgr = new XmlNamespaceManager(nt);
            nsmgr.AddNamespace("urn", "urn:nhibernate-mapping-2.2");
            XmlDocument doc = new XmlDocument(nt);
            doc.PreserveWhitespace = true;
            doc.LoadXml(internalStreams[stream[0]].ToString());
            XmlNode refChild = doc.SelectSingleNode("//urn:class",nsmgr);
            for (int i = 1; i < stream.Length; ++i)
            {
                XmlDocument docChild = new XmlDocument(nt);
                docChild.PreserveWhitespace = true;
                docChild.LoadXml(internalStreams[stream[i]].ToString());
                doc.SelectSingleNode("/urn:hibernate-mapping",nsmgr).AppendChild(doc.ImportNode(docChild.SelectSingleNode("//urn:class",nsmgr),true));
            }
            DiffConfiguration dc = new DiffConfiguration("test", true, WhitespaceHandling.None, true);
            XmlDiff diff = new XmlDiff(new XmlInput(doc.OuterXml)
                                       , new XmlInput(ResourceHelper.GetResource(hbm))
                                       ,dc
                                       );
            var res = diff.Compare();
            if (!res.Equal)
            {
                Console.WriteLine("Expected xml was:");
                Console.WriteLine(ResourceHelper.GetResource(hbm));
                Console.WriteLine("But was:");
                Console.WriteLine(doc.InnerXml);

            }
            Assert.IsTrue(res.Equal);
        }