Is it possible to mock overloaded instance methods with natural mocks? Seems like it works with static methods.
I have an implemenation of a database connection class that overloads the CreateCommand call such as:
public class MyDbConnection {
public MyDbCommand CreateCommand(string sql) {
return CreateCommand(sql, DEFAULT_TIMEOUT);
}
public MyDbCommand CreateCommand(string sql, int timeout) {
//implementation not important.
}
}
If I mock the call to CreateCommand like this:
using (RecordExpectations recorder = RecorderManager.StartRecording()) {
conn.CreateCommand(string.Empty);
recorder.CheckArguments(Check.CustomChecker(sqlVerify.SaveSql, null));
recorder.CallOriginal();
recorder.RepeatAlways();
}
I get an exception at runtime:
TypeMock.VerifyException:
TypeMock Verification: Call to TetraData.UnitTesting.Data.MockTDDbConnection.CreateCommand() 1 Parameters expected but received 2
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Object p1, Object p2)
at TetraData.Common.SQL.TDDbConnection.CreateCommand(String cmdText, Int32 commandTimeout) in TDDbConnection.cs:line 247
at TetraData.Common.SQL.TDDbConnection.CreateCommand(String cmdText) in TDDbConnection.cs:line 237
It looks like the first call to CreateCommand is mocked properly, but because the overload just routes it's implementation to the second overload, TypeMock doesn't seem to like it.
But if I add both overloads to the using block, then everything works as expected.
Is this how it is supposed to work? Is this in the documentation somewhere?