Reputation: 19279
I'm trying to unit test EventStore persistence using JSON serialization and Sqlite running in inmemory-mode. I'm getting a "No such table: Commits" exception during EventStore initialization. I'm assuming this is because EventStore somehow closes the connection and opens a new one, causing it to see a new in-memory Sqlite instance (sans Commits table). Is there any way to make this work?
Upvotes: 3
Views: 1132
Reputation: 5267
The SQLite implementation is interesting, especially when you're using the ":memory:" connection string. The acceptance tests surrounding the implementation depend upon the the database not "disappearing" between operations.
The fundamental design of the EventStore separates each discrete action into a separate operation which:
The issue that you're running into is that each invocation against the EventStore opens and closes the connection.
Now, there is a way around this because I wanted to support explicitly utilizing the same IDbConnection without releasing it back to the pool. EventStore v3.0 (which is in release candidate stage) has a method call that utilizes the same connection and which avoids connection tear down after each operation:
ConfigurationConnectionFactory.OpenScope("SQLite"); // SQLite = app.config connection key
Simply add this to the "using_the_persistence_engine" acceptance tests class and you're all set:
private static IDisposable scope;
Add this as the first line to "Establish context":
scope = ConfigurationConnectionFactory.OpenScope("SQLite");
Finally, the lastline in "Cleanup everything" should be:
scope.Dispose();
Upvotes: 3