February 19, 2010 NHibernate, QuickTip
February 19, 2010 NHibernate, QuickTip
What do you see to be wrong with this code?
.Add(Restrictions.Eq(“r.Name”, ruleName))
//other restrictions
.List();
return result.Count > 0;
}
At first I did not see any issues with it so I copied it and changed a bit for my another query. But current method is wrong. I discovered this with UTs.
First, Projections.RowCount() generates COUNT(*) in select statement.
This is query, which I got from my new Unit Tests: RuleExists_HitsDatabase_ThereIsNoRule.
Result of this query is number of rows like on picture below:
So, verification return result.Count > 0; is absolutely incorrect.
I’ve chagned it to return (int)result[0] > 0;
Moral:
Do not be lazy to write Unit Tests both for success and failure sceneries.
code
more code
~~~~