I\'ve read that when using moq you cannot mock a non-virtual function. I\'ve also read that this should be possible now.. Is that true? If so, then I\'d like to mock the f
What I have done to being able to Mock ExecuteSqlCommand, which is not possible to do in DataBase class, was to create the same method in my DbContext inheritance but this time virtual, and call the Database.ExecuteSqlCommand
public class MyDbContext : DbContext
{
public virtual int ExecuteSqlCommand(string sql, params object[] parameters)
{
return Database.ExecuteSqlCommand(sql, parameters);
}
public virtual int ExecuteSqlCommand(TransactionalBehavior transactionalBehavior, string sql, params object[] parameters)
{
return Database.ExecuteSqlCommand(transactionalBehavior, sql, parameters);
}
Then I changed my business code to call this created method (Not Database method):
DatabaseContext.ExecuteSqlCommand(updateQuery, newValue);
Then, it works