NHibernate SessionFactory Configuration for In‑Memory SQLite Tests Without Production Credentials
25.5K reputation · 21 Oct 2020, 19:19 UTC
Goal: configure NHibernate integration tests to run against an in‑memory SQLite database so that no production credentials are required, while guaranteeing that any mistake in the connection string is caught before the test suite starts.
Uncertainty: NHibernate reads the connection string from the configuration but does not open a physical connection until the first ISession is created; the SessionFactory construction may succeed even with an invalid string, deferring the error to runtime when a session is opened. This lazy connection resolution makes early‑failure detection in test harnesses unreliable.
- Does NHibernate validate the connection string (e.g., by attempting to open a connection) during ISessionFactory.BuildSessionFactory()?
- If validation is deferred, what configuration options or extension points can be used to force early connection verification in a test harness?
- How does this behavior differ between NHibernate 5.x and 6.x regarding lazy connection creation?