Esempio n. 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);
 }
Esempio n. 2
0
        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);
 }        
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 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);
     }
 }
Esempio n. 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);
 }
Esempio n. 7
0
 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));
     }
 }
Esempio n. 9
0
 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);
 }
Esempio n. 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");
 }
Esempio n. 13
0
 private void PerformAssertion(XmlDiff diff, bool assertion)
 {
     Assert.AreEqual(assertion, diff.Compare().Equal);
       Assert.AreEqual(assertion, diff.Compare().Identical);
 }
Esempio n. 14
0
 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);
 }
Esempio n. 15
0
 private void PerformAssertion(string control, string test, bool assertion)
 {
     XmlDiff diff = new XmlDiff(control, test);
       PerformAssertion(diff, assertion);
 }
Esempio n. 16
0
 public static void AssertXmlIdentical(XmlDiff xmlDiff)
 {
     AssertXmlIdentical(xmlDiff, true);
 }
Esempio n. 17
0
 public static void AssertXmlEquals(XmlDiff xmlDiff)
 {
     AssertXmlEquals(xmlDiff, true);
 }
Esempio n. 18
0
 private static void AssertXmlIdentical(XmlDiff xmlDiff, bool identicalOrNot)
 {
     DiffResult diffResult = xmlDiff.Compare();
     AssertEquals(xmlDiff.OptionalDescription, identicalOrNot, diffResult.Identical);
 }
Esempio n. 19
0
 public static void AreIdentical(XmlDiff xmlDiff, String message)
 {
     AreIdentical(xmlDiff, message, null);
 }
Esempio n. 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);
 }
Esempio n. 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);
              }
        }
Esempio n. 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);
              }
        }
Esempio n. 23
0
        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();
            });
              }
        }
Esempio n. 24
0
 public static void AssertXmlIdentical(XmlDiff xmlDiff)
 {
     AssertXmlIdentical(xmlDiff, true);
 }
Esempio n. 25
0
 public static void AreIdentical(XmlDiff xmlDiff)
 {
     AreIdentical(xmlDiff, String.Empty, null);
 }
Esempio n. 26
0
 public static void AssertXmlNotIdentical(XmlDiff xmlDiff)
 {
     AssertXmlIdentical(xmlDiff, false);
 }
Esempio n. 27
0
 private static void AssertXmlEquals(XmlDiff xmlDiff, bool equalOrNot)
 {
     DiffResult diffResult = xmlDiff.Compare();
     Assertion.AssertEquals(diffResult.StringValue, equalOrNot, diffResult.Equal);
 }
Esempio n. 28
0
 public static void AssertXmlNotIdentical(XmlDiff xmlDiff)
 {
     AssertXmlIdentical(xmlDiff, false);
 }
Esempio n. 29
0
 public static void AssertXmlEquals(XmlDiff xmlDiff)
 {
     AssertXmlEquals(xmlDiff, true);
 }
Esempio n. 30
0
 private DiffResult PerformDiff(TextReader reader1, TextReader reader2) {            
     _xmlDiff = new XmlDiff(reader1, reader2);
     DiffResult result = _xmlDiff.Compare();
     return result;
 }
Esempio n. 31
0
 public static void AssertXmlNotEquals(XmlDiff xmlDiff)
 {
     AssertXmlEquals(xmlDiff, false);
 }
Esempio n. 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;
		}
Esempio n. 34
0
        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);
        }