tags:

views:

78

answers:

4

I am using NHibernate as my ORM, and for unit testing purpose I am using sqlite as a substitute database.

In order to have meaningful unit test I need to populate the tables. How to do this in NHibernate? Even though my unit testing database is sqlite, I would prefer a db independent scripts that allow me to do that.

Does Nhibernate support this out of box? Or I have to resort to using NHibernate Save method to do the insertion?

P/S: Some of the ORM or framework in other language ( such as Symfony in PHP), supports this via yml.

A: 

Maybe this helps: FluentNHibernate.org they have a nice wiki introducing the usage:

http://wiki.fluentnhibernate.org/Getting_started#Schema_generation

Also have a look at the NHibernate documentation.

Henrik
Sorry-- it doesn't really help. Although it has schema generation, but I am more interested in **data population**; they are two different things, although related.
Ngu Soon Hui
Ah okay - missed that.
Henrik
A: 

I don't know of any tool that does this for you, but it would be nice.

Your idea to use the save method should work and it would be as database independent as the rest of your application.

I have a console application that pretty much does this, so I can load the initial data into the database for my main application to function.

quip
+1  A: 

AFAIK NHib does not give you a bulk import option ... you'll need to create some entities somehow and then call ISession.Save on them. If you go down this route, I recommend you consider the Test Data Builder pattern.

You could instead have some objects serialized to XML and then you will need to deserialize and save to setup your data, but I suspect the XML would be tedious to maintain.

John Rayner
I might just as well maintain it in my test code-- populate the tables with Session.Save in my test setup
Ngu Soon Hui
A: 

Have a look at this blog post by ScotMuc and the Autumn of Agile series by Stephen Bohlen. These should point you in the right direction

Nathan Fisher