Skip to content

Instantly share code, notes, and snippets.

@drmohundro
Created May 19, 2009 17:28
Show Gist options
  • Save drmohundro/114242 to your computer and use it in GitHub Desktop.
Save drmohundro/114242 to your computer and use it in GitHub Desktop.
Fluent NHibernate version of Ayende's InMemoryDatabaseTest
public class InMemoryDatabaseTest : IDisposable
{
private static Configuration _configuration;
private static ISessionFactory _sessionFactory;
protected ISession _session;
public InMemoryDatabaseTest(Assembly assemblyContainingMappedType)
{
if (_configuration == null)
_sessionFactory = CreateSessionFactory(assemblyContainingMappedType);
_session = _sessionFactory.OpenSession();
new SchemaExport(_configuration).Execute(true, true, false, true, _session.Connection, Console.Out);
}
private ISessionFactory CreateSessionFactory(Assembly assemblyContainingMappedType)
{
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory)
.Mappings(m => m.FluentMappings.AddFromAssembly(assemblyContainingMappedType))
.ExposeConfiguration(cfg => _configuration = cfg)
.BuildSessionFactory();
}
public void Dispose()
{
_session.Dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment