Cannot moq 'Execute' after mocking 'QuerySingle<int>'
I want to mock both QuerySingle and Execute functions. Mocking 'Execute' after QuerySingle throws error. The error says
Message:
- System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
-
SqlMapper.QueryRowImpl[T](IDbConnection cnn, Row row, CommandDefinition& command, Type effectiveType) line 1180
-
SqlMapper.QuerySingle[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable
1 commandTimeout, Nullable1 commandType) line 785 -
SqlMapper.QuerySingle(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable
1 commandTimeout, Nullable1 commandType) line 691
Please see the following example: var moqConnection = new Mock<IDbConnection>(); const int expected = -44;
moqConnection.SetupDapper(c => c.QuerySingle
var actual1 = moqConnection.Object.QuerySingle("yyy"); var actual2 = moqConnection.Object.Execute("zzz");
In the above example, if I swap 'QuerySingle' and 'Execute' then the code works.