Preloading data with SQLite
It is often desirable to preload the database with test data before running tests. In this recipe, we will show you how to load the in-memory database with data from a SQLite file database.
Getting ready
Complete the previous recipe, Fast-testing with the SQLite in-memory database.
Create a SQLite file database with the desired schema (tables and columns), 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.
How to do it...
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...