7

Does NUnit support (perhaps by using a third party libraries) a smart comparison for XML data.

Let's say we need to compare two xml files - the simplest way would be to compare xml content using the no-case sensitive string comparison, but that would only work in a trivial cases.

Is there any library around which could simplify xml comparison - e.g. some kind of XmlAssert?

The functionality I am after - "having a two xml files, compare these nodes (because they are important) and ignore the rest".

Similar questions

Community
  • 1
  • 1
Andrew
  • 295
  • 4
  • 10

3 Answers3

2

There is work on porting XMLUnit to .Net. I've only used the Java version, and don't know how complete the port is. It may not be ready for prime-time...

Don Roby
  • 40,677
  • 6
  • 91
  • 113
2

I was looking for the same kind of tool for .NET and found this: Jolt.NET. Going to try it myself.

oderibas
  • 1,575
  • 12
  • 20
1

I haven't used it myself at this point, but fluentassertions.com has a library addon for NUnit and other testing frameworks that allows for this type of assertion. Might be useful to someone.

xDocument.Should()
.HaveElement("child")
.Which.Should()
.BeOfType<XElement>()
.And.HaveAttribute("attr", "1");
Bakudan
  • 19,134
  • 9
  • 53
  • 73
Kelly Anderson
  • 121
  • 1
  • 8
  • I've now tried fluent assertions myself, and it does perform the exact test the original poster requested very nicely, even if my answer wasn't spot on. – Kelly Anderson Aug 20 '15 at 21:10