Skip to content

Instantly share code, notes, and snippets.

@markrendle
Created October 12, 2012 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markrendle/3879470 to your computer and use it in GitHub Desktop.
Save markrendle/3879470 to your computer and use it in GitHub Desktop.
DatabaseFactory class for Simple.Data + Impromptu
static class DatabaseFactory
{
public static IDatabase Create()
{
Database.UseMockAdapter(CreateMockAdapter());
// This single line of code applies all these interfaces
return Impromptu.ActLike<IDatabase>(Database.Open());
}
private static InMemoryAdapter CreateMockAdapter()
{
var inmem = new InMemoryAdapter(StringComparer.OrdinalIgnoreCase);
inmem.SetAutoIncrementKeyColumn("Customers", "Id");
inmem.SetAutoIncrementKeyColumn("Employees", "Id");
inmem.Join.Master("Customers", "Id", "Employees").Detail("Employees", "EmployerId", "Employer");
return inmem;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment