Question

For every entity that I create I write a unit test that just loads one record from the database to see if the query works and the data can be set on the entity correctly. You could see this as a unit test for the basic mapping. This should also confirm that a mapping file exists for the type and is set as embedded resource.

The test looks like this (test resides in generic base class):

session.CreateCriteria(typeof(TEntity)).SetMaxResults(1).List();

I don't do any assertions, I just want to see if this line works without throwing exceptions.

Now in one case I forgot to set the mapping file as embedded resource but the test still worked. No query was sent to the database however, so it basically didn't do anything.

Why doesn't CreateCriteria() or List() fail for an unmapped type? And how can I test for that specific requirement?

EDIT: If found that the following line does throw an exception, but still wondering about the first case

session.CreateCriteria(typeof(TEntity)).SetMaxResults(1).Future<TEntity>().ToArray()
Was it helpful?

Solution

I don't know, but apparently at NHibernate they don't know either. See https://nhibernate.jira.com/browse/NH-2183 for a bug that was reported on this issue. They're still working on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top