What do you see to be wrong with this code?

        public bool RuleExists(string ruleName, string documentName)
        {
            var result = Session.CreateCriteria(typeof(Rule)“r”)
                //some aliaces 
             
                .SetProjection(Projections.RowCount())

                .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.

SELECT count(* ) AS y0_
FROM   TBL_RULE this_
       INNER JOIN — some joins here
     
WHERE  this_.NAME = ‘absolultely_incorrect_rule_name’ /* @p0 */
       AND — other conditions 

Result of this query is number of rows like on picture below:

So, verification return result.Count > 0is 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.

If you haven't subsribed yet, you can subsribe below: