InMemoryDatabaseTest using FluentNHibernate

Ayende posted this wonderful idea before, Billy McCafferty also mentioned this to me during our NH training.

I created the FN syntax InMemoryDatabaseTestFixture based on Ayende’s code.

public class InMemoryDatabaseTestFixture : IDisposable
        private static Configuration Configuration;
        private static ISessionFactory SessionFactory;
        protected ISession session;

        public InMemoryDatabaseTestFixture(Assembly assemblyContainingMapping)
            if (Configuration == null)

                FluentConfiguration config = Fluently.Configure()
                    .Mappings(m =>
                                      m.AutoMappings.Add(new AutoPersistenceModelGenerator(assemblyContainingMapping).Generate());


                Configuration = config.BuildConfiguration();
                SessionFactory = config.BuildSessionFactory();

            session = SessionFactory.OpenSession();

            new SchemaExport(Configuration).Execute(true, true, false, session.Connection, Console.Out);

        public void Dispose()

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s