public void ExtractItems() { var outputDir = Path.Combine(GetTestProjectDir("ConsoleApp"), NativeExeOutputDirectory); var exe = Path.Combine(outputDir, "ConsoleApp.exe"); var fileName = Path.GetTempFileName(); Console.WriteLine("Using temp file: " + fileName); var result = BuildProject("ConsoleApp", targets: "ExtractItemsTest", properties: new { ExtractItemsOutputFile = fileName }); var expected1 = Resources.ExtractItemsTestExpected1.Replace("$(TestProjects)", TestProjectsRoot); Diff diff = DiffBuilder.Compare(Input.FromFile(fileName)) .WithDifferenceEvaluator(DifferenceEvaluators.IgnorePrologDifferences()) .WithTest(Input.FromString(expected1)) .Build(); Assert.IsFalse(diff.HasDifferences(), diff.ToString()); fileName = Path.GetTempFileName(); Console.WriteLine("Using temp file: " + fileName); var expected2 = Resources.ExtractItemsTestExpected2.Replace("$(TestProjects)", TestProjectsRoot); result = BuildProject("ConsoleApp", targets: "ExtractItemsTest", properties: new { ExtractItemsOutputFile = fileName, TestVariable = "Something" }); diff = DiffBuilder.Compare(Input.FromFile(fileName)) .WithDifferenceEvaluator(DifferenceEvaluators.IgnorePrologDifferences()) .WithTest(Input.FromString(expected2)) .Build(); Assert.IsFalse(diff.HasDifferences(), diff.ToString()); }
/// <summary> /// Adds placeholder support to an IDifferenceEngineConfigurer /// considering an additional DifferenceEvaluator. /// </summary> /// <param name="configurer">configurer the configurer to add support to</param> /// <param name="placeholderOpeningDelimiterRegex">regular /// expression for the opening delimiter of placeholder, /// defaults to /// PlaceholderDifferenceEvaluator#PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX /// if the parameter is null or blank</param> /// <param name="placeholderClosingDelimiterRegex">regular /// expression for the closing delimiter of placeholder, /// defaults to /// PlaceholderDifferenceEvaluator#PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX /// if the parameter is null or blank</param> /// <param name="evaluator">the additional evaluator - /// placeholder support is chained after the given /// evaluator.</param> /// <return>the configurer with placeholder support added in.</return> public static D WithPlaceholderSupportUsingDelimitersChainedAfter <D>(this D configurer, string placeholderOpeningDelimiterRegex, string placeholderClosingDelimiterRegex, DifferenceEvaluator evaluator) where D : IDifferenceEngineConfigurer <D> { return(configurer.WithDifferenceEvaluator(DifferenceEvaluators.Chain( evaluator, new PlaceholderDifferenceEvaluator(placeholderOpeningDelimiterRegex, placeholderClosingDelimiterRegex).Evaluate))); }
public void HasIgnorePlaceholder_Equal_NoWhitespaceInPlaceholder_CDATA_TEST() { string control = "<elem1><elem11>${xmlunit.ignore}</elem11></elem1>"; string test = "<elem1><elem11><![CDATA[abc]]></elem11></elem1>"; var diff = DiffBuilder.Compare(control).WithTest(test) .WithDifferenceEvaluator(DifferenceEvaluators.Chain( DifferenceEvaluators.Default, new PlaceholderDifferenceEvaluator().Evaluate)) .Build(); Assert.IsFalse(diff.HasDifferences()); }
public virtual bool IsEqual(XmlNode expected, XmlNode actual) { // XMLUnit's DiffBuilder - https://github.com/xmlunit/user-guide/wiki/DiffBuilder // Do NOT ignore whitespace because that trims text node values which is destructive and not equivalent in enterprise systems. this.differences = DiffBuilder.Compare(Input.FromNode(expected)) .WithTest(Input.FromNode(actual)) .IgnoreComments() .CheckForSimilar() // ignore child order, namespace prefixes etc - https://github.com/xmlunit/user-guide/wiki/DifferenceEvaluator#default-differenceevaluator .WithNodeMatcher(new DefaultNodeMatcher(ElementSelectors.ByName)) // allows for comparisons of nodes in different order .WithDifferenceEvaluator(DifferenceEvaluators.Chain(DifferenceEvaluators.Default, IgnoreElementTagNameDifferenceEvaluator.Evaluate)) .WithComparisonFormatter(this.comparisonFormatter) .Build(); return(!this.differences.HasDifferences()); }
private ComparisonResult IgnoreCaseDifferenceEvaluator(Org.XmlUnit.Diff.Comparison comparison, ComparisonResult outcome) { if (outcome == ComparisonResult.EQUAL) { return(outcome); } var controlNode = comparison.ControlDetails.Target?.OuterXml; var targetNode = comparison.TestDetails.Target?.OuterXml; if (string.Equals(controlNode, targetNode, StringComparison.InvariantCultureIgnoreCase)) { return(ComparisonResult.EQUAL); } return(DifferenceEvaluators.Default(comparison, outcome)); }
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()); }
private static Diff CreateDiff(string expectedHtml, string testHtml) { Diff?diffResult = null; Should.NotThrow(() => { var test = Input.FromString(WrapInTestRoot(testHtml)).Build(); var control = Input.FromString(WrapInTestRoot(expectedHtml)).Build(); diffResult = DiffBuilder.Compare(control) .IgnoreWhitespace() .WithTest(test) .WithDifferenceEvaluator(DifferenceEvaluators.Chain( DifferenceEvaluators.Default, RegexAttributeDifferenceEvaluator.Default, CssClassAttributeDifferenceEvaluator.Default) ) .Build(); }, CreateParseErrorText(expectedHtml, testHtml)); return(diffResult !); }