views:

72

answers:

1

I have a dozen or so named queries in my NHibernate project and I want to execute them against a test database in unit tests to make sure the syntax still matches the changing domain/database model. Currently I have a unit test for each named query where I get and execute the query, for example:

IQuery query = session.GetNamedQuery("GetPersonSummaries");
var personSummaryArray = query.List();
Assert.That(personSummaryArray, Is.Not.Null);

This works fine, but I would like to have one unit test that loops thru all of the named queries and executes them. Is there a way to discover all of the available named queries?

Thanks
Dan

+1  A: 

Configuration.NamedQueries has a list of named queries (it's an IDictionary, the key is the query name)

Of course, you'll need access to the Configuration instance, or save that list somewhere.

Diego Mijelshon
Yes, thank you.
Dan
FYI, there is also a NamedSqlQueries property to the Configuration object (which is what I actually needed).
Dan