UnoSD / Moq.Dapper

Moq extensions for Dapper methods.
GNU General Public License v2.0
173 stars 78 forks source link

ExecuteAsync with parameter #25

Open pauloasantos opened 6 years ago

pauloasantos commented 6 years ago

I'm using Moq.Dapper for my unit tests, however when i used with parameter, throw exception "Object reference not set to an instance of an object"

Example:

var connection = new Mock<DbConnection>();
connection.SetupDapperAsync(c => c.ExecuteAsync(It.IsAny<string>(), It.IsAny<UsuarioInfo>(), It.IsAny<DbTransaction>(), null, null)).ReturnsAsync(0);

await connection.Object.ExecuteAsync("@Login", new { Login = "test"}, null);

Can you help me?

laaladjelouah commented 6 years ago

I have the same problem and this is my StackTrace :

at ParamInfobbce6ce9-de83-4426-a005-45a32082c57f(IDbCommand , Object ) at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action2 paramReader) at Dapper.SqlMapper.TrySetupAsyncCommand(CommandDefinition command, IDbConnection cnn, Action2 paramReader) at Dapper.SqlMapper.<ExecuteImplAsync>d__39.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at xxx.Infrastructure.Data.xxxx.SqlServerRepository.d9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at xxx.SqlRepositoryTests.d1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Message du résultat : System.NullReferenceException : Object reference not set to an instance of an object. `

max7969 commented 6 years ago

Hi, I have exactly the same problem, is there any fix planned ? Thank's in advance.

UnoSD commented 6 years ago

@pauloasantos feel free to re-add the comment, I deleted it by mistake.

max7969 commented 6 years ago

I saw the comment but unfortunately I'm limited in the use of external NuGet :(. It's why I was asking if any correction was planned into Moq.Dapper.

UnoSD commented 6 years ago

@max7969 I will have some spare time at the end of November, I know it's not really close, but I am the only active contributor. Should be sorted then.

max7969 commented 6 years ago

@UnoSD Thank's for quick responding, end of the year is perfect ;)

aabragan commented 5 years ago

Is this issue resolved yet? I am still getting an error during the setup of the dapper mock. I am running v1.0.0.9. Thanks in advance! image

UnoSD commented 5 years ago

Hi everyone, apologies for not keeping my promise, but I did not manage to get to it yet. I won't make promises again, but if anyone makes a PR I'll jump on it quickly.

Al38andr0 commented 5 years ago

Same issue and same version as aabragan. Any update? Thank you.

1ewallace1 commented 4 years ago

I ran into the same issue as @aabragan when using Mock<IDbConnection>(). It was resolved when I used Mock<DbConnection>.

stevieray8450 commented 4 years ago

@1ewallace1 -- +1. This workaround also did the trick for me

https://dotnetfiddle.net/a2W4Ih

bupdaddy commented 3 years ago

Brilliant lifehack solution. Thanks!