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

Unable to moq dapper when using storedprocedure in c# ?

Open ankurjasoria opened this issue 5 years ago • 3 comments

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.

ankurjasoria avatar Mar 02 '19 20:03 ankurjasoria

Works fine for me:

conn.SetupDapper(c => c.Query<BusinessObj>(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.

darthmolen avatar Jun 06 '19 18:06 darthmolen

@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.

ricochetbrown avatar Jul 28 '19 12:07 ricochetbrown

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

UnoSD avatar Jul 31 '19 20:07 UnoSD