Does anybody know of a way to create a DataSet
such that when I call GetXml()
on the DataSet
I will get an exception? I'm trying to write some failure testing for this scenario and am having a hard time. Is it possible?
views:
74answers:
5
A:
You could simply throw the exception that a corrupted dataset would throw to emulate the problem
Bryan Denny
2010-03-23 16:11:26
No, the method I'm testing calls dataSet.GetXML() and I need that to fail so it will hit the catch block (trying to get full code coverage).
dcp
2010-03-23 16:13:30
You can refer to this link: http://bytes.com/topic/net/answers/827334-dataset-getxml-returns-child-row-has-multiple-parents-exceptionIt seems it is possible to get an exception.
dcp
2010-03-23 16:19:06
Interesting - I'll update my answer with a technique that should give you that exception.
jball
2010-03-23 16:22:28
A:
According to the documentation the DataSet.GetXML method does not throw exceptions.
It may return an empty string or null (although the docs don't say so) but it doesn't throw exceptions.
You might avoid exceptions by first checking if the resulting DataSet contain any errors (DataSet.HasErrors) or even go so far as to check every table (DataTable.HasErrors) and every row (DataRow.HasErrors)?
Are you sure about that? http://bytes.com/topic/net/answers/827334-dataset-getxml-returns-child-row-has-multiple-parents-exception
dcp
2010-03-23 16:14:30
A:
Could you pass a null DataSet object to those functions which are calling GetXML? :-)
ydobonmai
2010-03-23 16:15:33
+2
A:
Can you write a subclass of DataSet such that its getXml() predictably throws an Exception?
Jim Kiley
2010-03-23 16:23:47