I am going through some code from an open source example of a DDD project DDD Sample.Net and came across an 'interesting' SQLite base test fixture (full code in the link).
Whereas I normally use a connection string for SQLite:
"Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1")
This author is using a DbFile with it (which he sets up / deletes each test):
"Data Source={0};Version=3;New=True;", DatabaseFile)
What is the advantage of doing it this way?
Cheers,
Berryl
EDIT
The reason I suspect the may be an advantage is because the balance of code in that class (below) suggests that the author is neither unsophisticated nor naive. The advantage wouldn't likely be performance. Am guessing it might make SQLite more reliable across test runs, but that's why I asked :--)
protected IDisposable Scope(bool transactional)
{
return new ScopeImpl(SessionFactory, transactional);
}
protected IDisposable Scope(bool transactional, string description)
{
Console.WriteLine(description);
return Scope(transactional);
}
private class ScopeImpl : IDisposable
{
private readonly ISessionFactory _sessionFactory;
public ScopeImpl(ISessionFactory sessionFactory, bool transactional)
{
_sessionFactory = sessionFactory;
ISession session = _sessionFactory.OpenSession();
if (transactional)
{
session.BeginTransaction();
}
CurrentSessionContext.Bind(session);
}
public void Dispose()
{
ISession session = CurrentSessionContext.Unbind(_sessionFactory);
if (!IsInExceptionContext())
{
if (session.Transaction != null)
{
session.Transaction.Commit();
session.Transaction.Dispose();
}
}
session.Close();
}
/// <summary>
/// Checks if current code is running in finally block ater throwing exception.
/// </summary>
private static Boolean IsInExceptionContext()
{
return Marshal.GetExceptionPointers() != IntPtr.Zero || Marshal.GetExceptionCode() != 0;
}