I have a method that takes a System.Data.DataSet and uses it to construct an object. I am trying to mock the dataset in order to test that the method constructs the object properly.
The method I am testing is the following:
My test is the following:
When I run this test if fails when data is read from the dataset with the following exception:
"InvalidCastException : Object cannot be cast from DBNull to other types."
I have tried mocking the DataSet several different ways and cannot get the test to work.
Before this I attempted to create mock tables using
Mock.Create<DataTable>() and
Mock.Arrange(() => dataset.Tables[0]).Returns(mockTable)
but the test still would fail because dataset.Table[0] would throw a IndexOutOfRangeException.
How can I properly mock a DataSet?
Thanks