It is often desirable to preload the database with test data before running tests. In this recipe, I will show you how to quickly load the in-memory database with data from a SQLite file database.
Complete the previous recipe, Fast testing with SQLite in-memory database.
Create a SQLite file database with identical schema, containing test data. This can be accomplished in a number of ways. Perhaps the easiest is to export an in-memory database using SQLiteLoader.ExportData
from this recipe.
Add a new class named
SQLiteLoader
using the following code:private static ILog log = LogManager.GetLogger(typeof(SQLiteLoader)); private const string ATTACHED_DB = "asdfgaqwernb"; public void ImportData( SQLiteConnection conn, string sourceDataFile) { var tables = GetTableNames(conn); AttachDatabase(conn, sourceDataFile); foreach (var table in tables) { var sourceTable = string.Format("{0}.{1}", ATTACHED_DB, table); ...