I was building unit tests for Data access blocks and liked to replace a MySql db with Sqlite in memory database, which i could consider as mock and load with test values.
Sqlite is created as below
using (var connection = new SqliteConnection("" +new SqliteConnectionStringBuilder
{
DataSource = ":memory:"
}))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
//code to create table and load data
var connectionString=connection.ConnectionString
methodToBeTested(connectionString);
//Assert codes
}
}
MySql code that need to be unit tested is as below
methodToBeTested(string connectionString)
{
using (MySqlConnection cn = new MySqlConnection(connectionString))
{
cn.Open();//Exception->Unable to connect to any of the specified MySQL hosts
//other codes
}
}
The MySqlClient adapter throws exception while opening a SQLite db connection. Is there a way to achieve this?