Open Abinaya-Krishnan opened 3 years ago
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, Nullable1 commandTimeout, Nullable1 commandType) line 785
1 commandTimeout, Nullable
SqlMapper.QuerySingle(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable1 commandType) line 691
Please see the following example: var moqConnection = new Mock(); const int expected = -44;
moqConnection.SetupDapper(c => c.QuerySingle("yyy", null, null, null, null)).Returns(-4); moqConnection.SetupDapper(c => c.Execute("zzz", null, null, null, null)).Returns(-44);
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.
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, Nullable
1 commandType) line 785SqlMapper.QuerySingle(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable
1 commandTimeout, Nullable
1 commandType) line 691Please see the following example: var moqConnection = new Mock();
const int expected = -44;
moqConnection.SetupDapper(c => c.QuerySingle("yyy", null, null, null, null)).Returns(-4);
moqConnection.SetupDapper(c => c.Execute("zzz", null, null, null, null)).Returns(-44);
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.