-
Notifications
You must be signed in to change notification settings - Fork 7
Testing
When you're unit testing you'd generally like to avoid making actual database calls (for various reasons).
To that end we provide a simple way of mocking out all the SQL stuff in Dashing and replacing it with an in-memory version of the database.
Install-Package Dashing.Testing
When you define your IConfiguration simply provide an extra constructor that accepts an IEngine:
public class MyConfiguration : DefaultConfiguration {
public MyConfiguration(IEngine engine)
: base(ConfigurationManager.ConnectionStrings["DefaultDb"], engine) {
this.Init();
}
public MyConfiguration()
: base(ConfigurationManager.ConnectionStrings["DefaultDb"]) {
this.Init();
}
private void Init() {
this.AddNamespaceOf<Post>();
}
}
Then you can use the second constructor inside your test project.
var config = new MyConfiguration(new InMemoryEngine());
You can then use that configuration as normal, beginning new sessions, inserting data, updating data etc etc.
NOTE: Obviously any use of Dapper to run SQL won't work
!!! WARNING !!!
The implementation of InMemoryEngine, while not bad, may not exactly match what your database does nor does it (yet) implement a transactional model i.e. there's no rollback or committing.