Reputation: 25686
I'm new to NHibernate (+Fluent), and I can't decide on what's the best strategy when it comes to structuring my code to make it testable. I have a plain structure including a domain model, mappings to map the model to database, and a few classes with behavior which will work towards the model classes and do transactions for updating and reading out data from the database. I have more on top of this, but that's not relevant here.
Now, when it comes to the unit testing what seems natural to me is to inject something to the behavior classes such that they will get a SQLite database for testing, or the real database however this is configured. Does this make sense? What I can't decide is what to inject.
Am I on the right track? How should I strcuture my code for writing unit tests for code using NHibernate? Any best practices I should be aware of?
Upvotes: 2
Views: 2131
Reputation: 12611
You may want to check out this blog post by Ayende: Nhibernate Unit Testing. He has a test base class that configures the session with an in memory database (sql lite). This seems be similar to your third option.
Upvotes: 6