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(); } }
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); } }
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); } }
private static void XmlEquals(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); } }
private static void XmlIdentical(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 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 static void AssertXmlIdentical(XmlDiff xmlDiff, bool identicalOrNot) { DiffResult diffResult = xmlDiff.Compare(); AssertEquals(xmlDiff.OptionalDescription, identicalOrNot, diffResult.Identical); }
private static void AssertXmlEquals(XmlDiff xmlDiff, bool equalOrNot) { DiffResult diffResult = xmlDiff.Compare(); Assertion.AssertEquals(diffResult.StringValue, equalOrNot, diffResult.Equal); }
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(); }); } }
private void PerformAssertion(XmlDiff diff, bool assertion) { Assert.AreEqual(assertion, diff.Compare().Equal); Assert.AreEqual(assertion, diff.Compare().Identical); }
private DiffResult PerformDiff(TextReader reader1, TextReader reader2) { _xmlDiff = new XmlDiff(reader1, reader2); DiffResult result = _xmlDiff.Compare(); return result; }
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); }
/// <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); } }
/// <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); } }
private bool CompareXml(string expectedResult, string actualResult) { XmlDiff diff = new XmlDiff(expectedResult, actualResult); return diff.Compare().Equal; }
public void DefaultConfiguredToUseValidatingParser() { DiffConfiguration diffConfiguration = new DiffConfiguration(); Assertion.AssertEquals(DiffConfiguration.DEFAULT_USE_VALIDATING_PARSER, diffConfiguration.UseValidatingParser); 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 StreamReader(controlFileStream), new StreamReader(testFileStream)); diff.Compare(); Assertion.Fail("Expected validation failure"); } catch (XmlSchemaException e) { string message = e.Message; // to prevent 'unused variable' compiler warning } finally { controlFileStream.Close(); testFileStream.Close(); } }