开发者

Corrupted DataSet in .NET for failure testing

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?


Can you write a subclass of DataSet such that its getXml() predictably throws an Exception?


Could you pass a null DataSet object to those functions which are calling GetXML? :-)


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)?


This seems like testing for exceptions on ToString() calls. Some things don't need failure testing.

You would get exceptions on creating/adding to a DataSet, so once you have a DataSet in memory that hasn't thrown an exception yet, it will always have a structure that allows GetXml() to work unexceptionally.

Update: looks like you can get it to throw an exception if you have two tables with a one-to-many relationship between them, set up the adapter to select multiple rows from the child table with the parent table info included in them, and then call GetXml().


You could simply throw the exception that a corrupted dataset would throw to emulate the problem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜