Garry Shutler
Garry Shutler

Reputation: 32698

Verifying contents of NHibernate Criteria

I'm looking to build complex queries using the NHibernate Criteria API. I'd like to verify that the criteria is constructed as I would expect without having to actually run the query.

Is this possible? Are there any tips or techniques for doing it elegantly?

Upvotes: 1

Views: 330

Answers (1)

Hibri
Hibri

Reputation: 426

A co-worker recently did this

encapsulate each criteria query in it's own class (specification). built an expression builder that will spit out the query to the string. tested that the generated expression string matches the expected expression string.

the expression builder walked the criteria tree in a specification in a recursive fashion to generate the expression string.

that's the general idea, don't have the code with me right now :) sorry.

However, I've found that it's much easier to write db integration tests to test Nh criteria. Does the criteria really return the data I expect.

Upvotes: 2

Related Questions