'Moq multiple generics i.e. LoadData<T,U>(string sproc)

I think I'm close, but just can't get the syntax. What am I missing for the Moq on this ?

https://dotnetfiddle.net/1RItB5

Method to test

public async Task<T> LoadSingleData<T, U>(string storedProcedure, U parameters)
{
   //An IDbConnection is injected at the ctor
    return await connection.QuerySingleOrDefaultAsync<T>(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
}

Test

[Fact]
public async Task<PatientHeaderInfo> GetAsyncShouldPass()
{          
    Mock<IDbConnection> mockDbConnection = new ();
    Mock<ISqlDataAccess> mockSqlDataAccess = new();
    dynamic param = new { id = 1 };
    mockSqlDataAccess.Setup(d => d.LoadSingleData<It.IsAny<It.IsAnyType>(), It.IsAny<It.IsAnyType>()> (It.IsAny<string>(), It.Is<dynamic>()))
                     .Returns<PatientHeaderinInfo>( b=> new PatientHeaderinInfo());

    var sut =  new SqlDataAccess(mockDbConnection.Object);
    Assert.NotNull(sut.LoadSingleData<PatientHeaderInfo, dynamic>("somesproc", param));
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source