Moq.Dapper icon indicating copy to clipboard operation
Moq.Dapper copied to clipboard

QueryAsync returns no records

Open molynerd opened this issue 1 year ago • 0 comments

Either I've configured something incorrectly, or QueryAsync doesn't work.

  • xunit 2.4.2
  • Dapper 2.0.151
  • Moq 4.20.69
  • Moq.Dapper 1.0.7
public class SomethingToMock
{
    private string Key;

    public SomethingToMock(string key)
    {
        Key = key;
    }
}

[Fact]
public async Task DoesMoqDapperWork()
{
    var connection = new Mock<IDbConnection>();

    var expected = new[]
    {
        new SomethingToMock ("asdf")
    };

    connection.SetupDapperAsync(c => c.QueryAsync<SomethingToMock>(It.IsAny<string>(), null, null, null, null))
        .ReturnsAsync(expected);

    var data = await connection.Object.QueryAsync<SomethingToMock>("foo");
    Assert.Equal(expected.Length, data.Count());
}

molynerd avatar Aug 22 '23 15:08 molynerd