|
| 1 | +# XMLUnit.NET |
| 2 | + |
| 3 | +XMLUnit provides you with the tools to verify the XML you emit is the |
| 4 | +one you want to create. |
| 5 | + |
| 6 | +This package provides a way to simplify comparisons by using a control |
| 7 | +document with a simple expression language to compare against. |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +XMLUnit requires .NET Standard 2.0 (tested with .NET 8 rigt now) and |
| 12 | +should still support .NET Framework 3.5 and Mono. |
| 13 | + |
| 14 | +The placeholders package only depends on XMLUnit.Core. |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +More documentaion is available as part of |
| 19 | +the [user guide](https://github.com/xmlunit/user-guide/wiki). |
| 20 | + |
| 21 | +If you are creating documents with a structure like |
| 22 | + |
| 23 | +```xml |
| 24 | +<message> |
| 25 | + <id>12345</id> |
| 26 | + <content>Hello</content> |
| 27 | +</message> |
| 28 | +``` |
| 29 | + |
| 30 | +and can't predict the `id` inside your tests but still want to assert |
| 31 | +it is a number, using just the core library will require some custom |
| 32 | +code as a `IDifferenceEvaluator` |
| 33 | + |
| 34 | +Using the placeholders package you can write a control document like |
| 35 | + |
| 36 | +```xml |
| 37 | +<message> |
| 38 | + <id>${xmlunit.isNumber}</id> |
| 39 | + <content>Hello</content> |
| 40 | +</message> |
| 41 | +``` |
| 42 | + |
| 43 | +and run the test like |
| 44 | + |
| 45 | +```csharp |
| 46 | +string control = <the above>; |
| 47 | +string test = <the program output>; |
| 48 | +Diff diff = DiffBuilder.Compare(control).WithTest(test) |
| 49 | + .WithDifferenceEvaluator(new PlaceholderDifferenceEvaluator()).build(); |
| 50 | +Assert.IsFalse(d.HasDifferences()); |
| 51 | +``` |
| 52 | + |
| 53 | +Currently the fillowing placeholders are defined: |
| 54 | + |
| 55 | +* `${xmlunit.ignore}` to completely ignore the element |
| 56 | +* `${xmlunit.isNumber}` |
| 57 | +* `${xmlunit.matchesRegex()}` with regex parameter |
| 58 | +* `${xmlunit.isDateTime()}` with optional format parameter |
| 59 | + |
| 60 | +## Additional Documentation |
| 61 | + |
| 62 | +XMLUnit.NET is developed at |
| 63 | +[github](https://github.com/xmlunit/xmlunit.net). More documentation, |
| 64 | +releases and an issue tracker can be found there. |
| 65 | + |
| 66 | +## Changelog |
| 67 | + |
| 68 | +See the [Release |
| 69 | +Notes](https://github.com/xmlunit/xmlunit.net/blob/main/RELEASE_NOTES.md) |
| 70 | +at github. |
0 commit comments