Mocking ISession.Query <T> () for consumer testing

I am trying to avoid using a database in memory for testing (although I may have to do this if the following is not possible). I am using NHibernate 3.0 with LINQ. I would like to be able to scoff at session.Query<T>()to return some dummy values, but I cannot, as this is an extension method, and it is almost impossible to verify.

Does anyone have any suggestions (other than using a database in memory) for testing session requests using LINQ?

+3
source share
3 answers

I tried this before with previous versions of NH without much luck. In the end, I used another class to wrap the request and laugh at it.

I really think it's worth writing an integration test with a real sql server to make sure that the repository behaves as expected.

+3
source

A better approach would be to falsify the concept of what you are trying to do, rather than the internal api of the external system. For instance,

  • Write the query in a split artifact like IQuerySomething / QuerySomething
  • Check your database request. Try this database to be prety like real db.
  • When testing something that depends on IQuerySomething, mock IQuerySomething.

Fabio Molo wrote about this template as an EQO (Extended Request Object), I recommend you post it.

.net .

0

, . =)

, , ( , , ). . ( , , "" ), .

, - .

, , , , , Fluent Nhibernate ( ) ), .

, , ( Linq), . , , , :

get-customer-by-name, .

, . .

, , José F. Romaniello, Enhanced Query Object .

Sharp Arhitecture framework, Nhibernate .

0

Source: https://habr.com/ru/post/1785539/


All Articles