I'm trying to mock IDataReader, found some code in previous posts that should work, but unfortunatly I can't get it to work.
I'm using the microsoft daab and the sqlhelper class.
My code is as follows:
Mock sqlHelperMock = MockManager.Mock(typeof(SqlHelper));
MockObject mockIDataReader = MockManager.MockObject(typeof(IDataReader));
sqlHelperMock.ExpectAndReturn("ExecuteReader", mockIDataReader as IDataReader);
mockIDataReader.ExpectAndReturn("Read", true);
// call some legacy code.
myObj.doSomeDataAccess..
In the dataaccess method code looks like:
IDataReader someDataReader = SqlHelper.ExecuteReader(ConnectionString,
CommandType.StoredProcedure,
"GetSomeData",
sqlParams);
if (someDataReader != null)
if (someDataReader.Read())
someDataReader should be mocked, but is always null so no read is called and mocking fails..
Should this work or am i doing something wrong?