Created
August 12, 2009 21:31
-
-
Save defeated/166781 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using NHibernate; | |
using FluentNHibernate.Conventions.Helpers; | |
using FluentNHibernate.Cfg.Db; | |
using FluentNHibernate.Testing; | |
namespace your.namespace.Tests { | |
/// <summary> | |
/// Base class for integration tests. | |
/// Sets up a fast, temporary instance of SQLite running in-memory for use in persistence tests. | |
/// </summary> | |
public class FluentNhibernateInMemoryDatabaseFixture { | |
protected static SingleConnectionSessionSourceForSQLiteInMemoryTesting SessionSource; | |
protected ISession session; | |
/// <summary> | |
/// Initializes a new instance of the <see cref="FluentNhibernateInMemoryDatabaseFixture" /> class. | |
/// Creates the single session and builds the database schema. | |
/// </summary> | |
public FluentNhibernateInMemoryDatabaseFixture() { | |
CreateSessionSource(); | |
this.session = SessionSource.CreateSession(); | |
SessionSource.BuildSchema(true); | |
} | |
private static void CreateSessionSource() { | |
if(SessionSource != null) return; | |
var config = SQLiteConfiguration.Standard.InMemory().ShowSql().ToProperties(); | |
var model = new DomainPersistenceModel() // a subclass of FNH AutoPersistenceModel with my project's conventions | |
.ConventionDiscovery.Add(DefaultLazy.AlwaysFalse()); // no proxy classes for specification tests | |
SessionSource = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(config, model); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment