Ugh, validating XML output. Welcome to hell :)
A method that has worked for me was to generate an XmlDocument
object in memory. Then run your SaveFile method, and load it into another XmlDocument
. Walk both XmlDocuments recursively, comparing all elements and attributes.
Unfortunately, writing xml with C# objects is big and bulky. I'd recommend testing subsections at a time. Maybe your save file has a <FileList>
sub element, a <Cups>
sub element, and <Rifles>
sub element. In that case, write a series of tests to ensure that each sub section is done correctly, instead of the overall output.