LoggingSqlCommand is just a wrapper around SqlCommand that does logging on 'Execute' methods...nothing fancy...when we 'CreateCommand' in are ADO.NET code we are getting back one of these objects.
So here's the 'mocking' - I want CallOriginal on the LoggingSqlCommand because later I want to check to make sure a parameter in the Parameters collection is present (if faked, can't do that).
SqlConnection mockConnection = Isolate.Fake.Instance<SqlConnection>(Members.CallOriginal);
Isolate.Swap.NextInstance<SqlConnection>().With(mockConnection);
Isolate.WhenCalled(() => mockConnection.Open()).IgnoreCall();
Isolate.WhenCalled(() => mockConnection.Close()).IgnoreCall();
LoggingSqlCommand mockCommand = Isolate.Fake.Instance<LoggingSqlCommand>(Members.CallOriginal);*****
Isolate.Swap.NextInstance<LoggingSqlCommand>().With(mockCommand);
Isolate.WhenCalled(() => mockCommand.ExecuteScalar()).WillReturn(-1);
Problem is when I create LoggingSqlCommand fake (where I have the *****), the constructor is being called which throws a null reference exception... why is the constructor being called?
public LoggingSqlCommand(SqlCommand cmd)
{
if (cmd == null)
{
throw new ArgumentNullException("cmd");
}
_internalCommand = cmd;
}
So if I use the default behavior I'm fine...but that won't help me determine if a parameter is present in the Parameters collection because now the Parameters collection is fake.