I need to create a unit test for a method that returns an xmldocument. What should I be validating in such a case? The method checks a database and creates an xmldocument and sends back the data to the client.
Should I look if the xmldocument returned has all expected xml tags? or should I have a Expected.xml file and match the xmldocument returned with this xml file. If I am going by the second approach, then whatever I am searching for is not present in database then this test would always fail. I want to write a test that is not dependent on any particular data but should check whether the data returned by the method is proper or not, so I am leaning towards the approach of checking only the tags and assuming that if tags are there and the values in these tags are also correct.
Lets assume i writing this test for a library application that gives a list of all books issued to a particular member. Members are identified by a id and let that be string:
<Member id="">
<Book>
<Name>Book_name</Name>
<Author>author</Author>
<Due_date>due date </Due_Data>
</Book>
</Member>
So i need to verify whether my method would return an xmlfile like above. And i need to verify that the tags are correct and it contains value (and not null values).
What do you think should be better approach? If someone has dealt with such situations before, it would be great if you can share your experience.
Thanks,