UnoSD / Moq.Dapper

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

Support for dynamic methods #23

Open UnoSD opened 6 years ago

UnoSD commented 6 years ago

See #22

DavidKorn commented 6 years ago

We need dynamic method support too, so I'm thinking of forking and adding it, but before I do I wanted to make sure nobody else was already about to release this. Are you actively working on it @UnoSD ?

UnoSD commented 6 years ago

@DavidKorn not at the moment, I had some spare time and I went through the issues from the oldest, I'll be happy to review when I get a chance if you want to contribute.

rogeryamato commented 5 years ago

So @UnoSD what's the status now? Can I use dynamic for UT?

mcalvinsf commented 5 years ago

I also cannot get mocking QueryAsync to work with my own types either. Is there any similar solution yet ?

I have tried something like the following ... ` [Fact] public async Task QueryAsyncGeneric() { var connection = new Mock();

        var expected = new List<ObjectTypeOperation>()
        {
            new ObjectTypeOperation(ObjectTypes.DataDictionary, Operation.ManageData),
            new ObjectTypeOperation(ObjectTypes.Account, Operation.View)
        };

        SetupToReturn(connection, expected);
        var actual = (await connection.Object.QueryAsync<ObjectTypeOperation>("", null, null, null, null )).ToList();

    }

    private void SetupToReturn<T>(Mock<DbConnection> conn, IEnumerable<T> results)
    {
        conn
            .SetupDapperAsync(mc => mc.QueryAsync<T>(It.IsAny<string>(), It.IsAny<object>(), null, null, It.IsAny<CommandType>()))
            .ReturnsAsync(results);
    }

I found that the issues lies in the fact that ObjectTypeOperation has enum properties. So apparently Moq.Dapper does not currently support this. When I changed the properties to int the test works.