File Comparators
Plain File Comparator
Create an instance of the comparator by providing the file paths of the two files that are going to be compared, for example:
var comparator = PlainFileComparator.Create(myFilepath1, myFilepath2);
// Performing a custom assertion over the comparator instance.
comparator.Compare().Validate(result => result);
Additionally the comparator can generate a verbose output that will help you to identify differences found within the files. Example:
comparator.ResultsInOutput = true; // This setting is "false" by default.
comparator.ResultType = PlainComparisonResult.PrettyHtml;
comparator.Compare();
If the files have differences, the comparator will generate a file with the prefix plaindiff and extension .html with the results.
XML File Comparator
This comparator works similar to the Plain File Comparator because both are based in the same class. Here is an example:
var comparator = new XmlFileComparator(expectedXmlPath, actualXmlPath)
{
ResultsInOutput = true,
XPathsInDescriptions = true,
};
comparator.CompareExcludingNodesByXPath("/Document/Parents").Validate(result => result);
comparator.CompareNodesByXPath("//Name", "//Priority", "//Goods").Validate(result => !result);
Last updated
Was this helpful?