Hi,
Consider the following section of a unit test;
SqlCeCommand command = Isolate.Fake.Instance<SqlCeCommand>(Members.ReturnRecursiveFakes);
Isolate.Swap.AllInstances<SqlCeCommand>().With(command);
SqlCeDataReader reader = Isolate.Fake.Instance<SqlCeDataReader>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => reader.Read()).WillReturn(true);
Isolate.WhenCalled(() => reader.Read()).WillReturn(false);
Isolate.WhenCalled(() => command.ExecuteReader()).WillReturn(reader);
The section of code under test is essentially the following;
using (SqlCeCommand command = new SqlCeCommand("SQL STATEMENT", _connection))
{
using (SqlCeDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
...
}
}
_connection.Close();
}
The unit test runs through fine, at the end however it appears to be trying to finalize the SqlCeDataReader and causing an exception. I've tried calling GC.SupressFinalize(reader) both before and after the method under test is executed but the same exception is raised.
I guess that the following line of code from the unit test is actually not changing the reference of the underlying data reader;
Isolate.WhenCalled(() => command.ExecuteReader()).WillReturn(reader);
And so the SupressFinalize is only relative to the data reader created within the context of the unit test.
Is there anyway of suppressing the finalizer for the data reader within the method under test?
Thanks
Steve.