Issue mocking(moq) ExecuteAsync for unit test(xunit)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
a moq of ExecuteAsync in my unit testing is throwingInnerException = {"Async operations require use of a DbConnection or an IDbConnection where .CreateCommand() returns a DbCommand"}. Execute seems to work fine.
private void SetupExecuteAsync ()
{
var dataParameterCollection = new Mock<IDataParameterCollection>();
dbCommandMock.Setup(x => x.Parameters).Returns(dataParameterCollection.Object);
dbCommandMock.Setup(x => x.ExecuteNonQuery()).Returns(It.IsAny<int>());
dbConnectionMock.Setup(s => s.CreateCommand()).Returns(dbCommandMock.Object);
}
I am mocking DbCommand object and Execute and ExecuteAsync seem to have the same parameters so I'm not sure why I am getting this error.
return connection.Execute(sql, dbParams, commandType: commandType);
vs
return await connection.ExecuteAsync(sql, dbParams, commandType: commandType).ConfigureAwait(false);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin at Dapper's ExecuteAsync entry point and compare it with Execute, then trace the connection's CreateCommand path and the DbCommand setup shown in SetupExecuteAsync. Reproduce the xunit/Moq failure and verify that the async call completes without the reported DbConnection/DbCommand exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- database, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100