In entity framework, DBContext is not thread-safe. In order to support multi-thread environment, I had to initialize a new DbContext based on a connection string every time a communication with SQL is needed.
private void function(string sqlConnectionString)
{
using (var dbContext = new DbContext(sqlConnectionString))
{
// talk to sql here
}
}
Now the unit test becomes tricky. Since DbContext is buried in the code, there is no way for me to pass in a mocked DbContext.
I looked online but didn't find a good solution. Any suggestions?