UnoSD / Moq.Dapper

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

Unable to moq dapper when using storedprocedure in c# ? #39

Open ankurjasoria opened 5 years ago

ankurjasoria commented 5 years ago

Hi All.

I am currently using Dapper in my .net application but unable to make Unit Test for Dapper when I am currently using stored procedure not inline queries.

Please help me for same.

darthmolen commented 5 years ago

Works fine for me:

conn.SetupDapper(c => c.Query(It.IsAny(), new { Account = It.IsAny() }, null, false, null, CommandType.StoredProcedure)).Returns(new BusinessObj[] { obj });

However, you can't use something like c.QueryFirst as it will give a "not supported" error message.

ricochetbrown commented 5 years ago

@ankurjasoria you can use stored procedures with this just fine. You can do something like this:

connection.SetupDapperAsync(c => c.QueryAsync<T>( It.IsAny<string>(), new DynamicParameters(), null, null, CommandType.StoredProcedure )).ReturnsAsync(expected);

@darthmolen every dapper function isn't in this library yet. QueryFirst is one that isn't.

UnoSD commented 5 years ago

@ankurjasoria can you show us some code? does what @darthmolen and @ricochetbrown work for you?