In my last post I shown how to create a SqlCe database “on the fly” once before all integration tests. Alexander asked me how can do the same thing but using a Microsoft Sql database. Let’ s how we can do it:
using (IDbConnection connection = new SqlCeConnection(masterConnectionString)) { connection.Open(); using (IDbCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "CREATE DATABASE UnitTestDemo"; command.ExecuteNonQuery(); } } }
//open a new connection to UnitTestDemo database and create all objects