Open GreenDavidA opened 4 years ago
QueryAsync method isn't working with null, it always expect a IEnumerable object and iterates over it.
At DbDataReaderFactory it needs to do something like this to work:
var result = resultFunc();
if (result == null)
return new DataTableReader(new DataTable());
I can confirm, it still has this issue. using Moq.Dapper, Version=1.0.4
I am trying to mock out a dependency that uses Dapper, and I want it to return null. Normally, when I am using Moq, I will cast the null as the return type, and it works. When I do that here, I am getting a
System.NullReferenceException
.The code is as follows:
The exception returned is:b 1()
--- End of stack trace from previous location where exception was thrown ---
Extensions.InvokePreserveStack(Delegate del, Object[] args)
ReturnLazyValueResponse.RespondTo(Invocation invocation)
MethodCall.Execute(Invocation invocation)
FindAndExecuteMatchingSetup.Handle(Invocation invocation, Mock mock)
IInterceptor.Intercept(Invocation invocation)
Interceptor.Intercept(IInvocation invocation)
AbstractInvocation.Proceed()
DbCommandProxy.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) line 419
TableDomainTests.Test1() line 148
--- End of stack trace from previous location where exception was thrown ---`
Message: System.NullReferenceException : Object reference not set to an instance of an object. Stack Trace: DbDataReaderFactory.DbDataReader[TResult](Func
1 result) <>cDisplayClass2_01.<SetupQueryAsync>b__1() <>c__DisplayClass2_0
2.I do have a workaround. In place of returning a null, I return an empty
List
and it does work.I just wanted to bring it to your attention.