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);
// call some legacy code.
In the dataaccess method code looks like:
IDataReader someDataReader = SqlHelper.ExecuteReader(ConnectionString,
if (someDataReader != null)
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?