I have to agree with Radim that the nhibernate code testing module, making fun of nhibernate functionality in most cases, is not what you want to do.
If you donโt want to test complex business logic based on the data you extract using nhibernate, then this is perfectly normal.
But to check if your mappings, search and save data work, you need to test a real database.
If you aim at MSSQL Server, I would not use another type of database. Instead, there is SQL Express, which has all the features of a real server. MSSQL Express can be installed from a local database. This will allow you to download mdf files through the connection string, which will more or less create an instance of the MSSQL server ...
I used this to test integration, and it works very well.
- Create a database file in a unit test project
- Depending on your model (/ db code first), let nhibernate create a schema, otherwise just fill in the schema in this database file
- Add the file to the deployment elements of your test settings so that the file is copied to the target destination directory
- Create a connection string that uses the copied database file. Example connection string:
Data Source=(LocalDB)\v11.0;AttachDbFileName=[whateverthepathis]\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True - Run tests
Thus, your tests will be run with an empty database every time, and you will have reproducible integration tests without the need for a real server, where you had to create a database or reset each time ...
source share