In Memory SQLite + Unit Test + FluentNHibernate

UPDATE:

I have forked fluent NH here: http://github.com/stefansedich/fluent-nhibernate, and added a change so we can just use:

.Database(SQLiteConfiguration.Standard.InMemory().ShowSql())

By default the InMemory() helper will now add the pooling support, I sent a push request, so hopefully this hits trunk. Not sure if I was being silly but I do not see a need where you would not pool in memory SQLite anyway.

----------------------------------------------------------

Just playing around with FNH for the first time, getting my unit tests running proved to be a pain, did a Google and had no luck finding a solution to my problem.

A quick play using the fluent config I found a way to get it working, my full session factory setup is below:

public ISessionFactory GetSessionFactory() { return Fluently.Configure() .Database(SQLiteConfiguration.Standard.InMemory() .ConnectionString("Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1;")) .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(CustomerRepository).Assembly)) .ExposeConfiguration(config => new SchemaExport(config).Create(true, true)) .BuildSessionFactory(); }

The key was to set the Pooling=True;Max PoolSize=1; in my config, looking at fluent NH the .InMemory() shortcut seems to not set these:

public SQLiteConfiguration InMemory() { Raw("connection.release_mode", "on_close"); return ConnectionString(c => c .Is("Data Source=:memory:;Version=3;New=True;")); }

Guess it would be great if it did, but for the time being I will just do it manually.


Cheers
Stefan

2 Comments

Comments have been disabled for this content.