Created
May 19, 2009 17:28
-
-
Save drmohundro/114242 to your computer and use it in GitHub Desktop.
Fluent NHibernate version of Ayende's InMemoryDatabaseTest
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
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