Created
October 12, 2012 14:30
-
-
Save markrendle/3879470 to your computer and use it in GitHub Desktop.
DatabaseFactory class for Simple.Data + Impromptu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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