I'm writing unit tests for one of our products and have been used Moq to successfully mock connections to Entity Framework. However, I've come across the following method:
public static productValue findValues(string productName, string dbConnectionString)
{
try
{
SqlConnection conn = new SqlConnection(dbConnectionString);
conn.Open();
//Do stuff
}
}
Which accesses our database inside that method using a passed connection string. Is it possible to setup a mock DB using Moq and create a connection string which points to the mocked DB? I've trying doing something along the lines of
var mockSqlConnnection = new Mock<SqlConnection>();
Though I'm unsure if this is the correct approach, as this would mock the connection itself rather than the DB.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…