huysentruitw / entity-framework-core-mock

Easy Mock wrapper for mocking EFCore5 DbContext and DbSet using Moq or NSubstitute
MIT License
132 stars 24 forks source link

Mock _dbContext.Database, ExecuteSqlCommandAsync in EFCore #7

Closed cbjpdev closed 5 years ago

cbjpdev commented 5 years ago

Hi,

I want to mock ExecuteSqlCommandAsync and ExecuteReader. We have to use these due to specific reason. This may not be a feature request. Please explain me how to achieve mocking these?

case 1: using (var command = _dbContext.Database.GetDbConnection().CreateCommand()) { command.CommandText = string.Format("select NEXT VALUE FOR {0}", sequenceName); _dbContext.Database.OpenConnection(); using (var result = command.ExecuteReader()) { if (result.Read()) { seqValue = result[0].ToString(); } } }

case 2: createdCount = await _reapContext.Database.ExecuteSqlCommandAsync(createSql);

huysentruitw commented 5 years ago

I think you need to use an integration test to cover that. There's no use in mocking a reader like that in my opinion.

cbjpdev commented 5 years ago

Yes, that would be the option. Anyway I added few interfaces and mocking these. No blocker for the moment. Can test these in the integration testing.

huysentruitw commented 5 years ago

Ok I'll close it for now. If you have any specific request regarding this which could benifit the library, feel free to reopen.