My 2 cents if that counts :)

Personally I have gone down this route before with testing
repositories, but in the end found that mocking session calls just
becomes WAY too hard. I guess you ask yourself what value do you get
from mocking your queries against the session?

IMO this is very little value, I get a lot more by actually making
these an integration test against my database. Now this does 2 things
for me, it verifies that my mapping files are correct and it tests my
repository code. So we see here that doing a test like this has a
greater return on my effort.

The other thing if you use something like NDBUnit, you can make these
tests better, we are able to put our database into a consistent state
at the start of each test run, and by using something like SQLite as
an in memory database we are able to make these tests quick to run.


This is just the conclusion I came to after writing many fragile tests
mocking session calls. But as I say have a look at NDBUnit, and in
particular if you wan't to see how it is done have a watch through the
Summer of NHibernate screen casts as this is shown there.



Cheers
Stefan

On Fri, Jan 16, 2009 at 7:36 AM, Roger Kratz <[email protected]> wrote:
>
> <<It's a lot easier to create an in-memory list of customers to query against 
> than setup records in the db.>>
> Why? Maybe I'm missing something but...
> inMemList.Add() vs repository.Add() is pretty similar?
>
>
> ________________________________
> Från: [email protected] [[email protected]] för Troy Tuttle 
> [[email protected]]
> Skickat: den 15 januari 2009 22:29
> Till: [email protected]
> Ämne: [nhusers] Re: Testing NHibernate, Mocking ISession
>
> That's what we are currently doing now, but as the domain model grows, the 
> integration tests can get huge when testing queries with multiple criteria 
> (like a search screen).  I'm finding most of the work is in getting the 
> database in the correct state for these kinds of respository/integration 
> testing.  So, my thought is, just test the integration by using 
> PersistenceSpecification.VerifyTheMappings(), and test the queries in 
> isolation (mocked). It's a lot easier to create an in-memory list of 
> customers to query against than setup records in the db.
>
> Thanks for the feedback though.
>
> tt
>
> On Thu, Jan 15, 2009 at 2:47 PM, isaiah perumalla 
> <[email protected]<mailto:[email protected]>> wrote:
>
> In my experience, i found it useful to simply write integration-tests
> to test the repositories.
> I generally avoid mocking 3rd party type such as ISession since the
> interaction tests will most like be quite fragile
>
> On Jan 15, 1:22 pm, "John Teague" 
> <[email protected]<mailto:[email protected]>> wrote:
>> Are you testing business logic that is using your repository, or are you
>> testing the repository itself?
>>
>> On Thu, Jan 15, 2009 at 1:23 PM, Troy T. 
>> <[email protected]<mailto:[email protected]>> wrote:
>>
>> > Hi,
>> > I'm using Linq to NH in a project, and would like to test my
>> > repository code without hitting the database.  I have code in my
>> > repository as:
>>
>> > public class Repository :  IRepository
>> > {
>> >     (... code snipped for brevity ...)
>>
>> >     public T FindBy<T>(Expression<Func<T, bool>> where)
>> >     {
>> >         return _session.Linq<T>().Where(where).FirstOrDefault();
>> >     }
>>
>> > }
>>
>> > Where _session is injected into the repository class as ISession.
>> > Does anyone have some ideas on how to test this repository query code
>> > without hitting the database?  I'm using Rhinomocks for mocking.
>>
>> > My idea is to create a List<T> of Customer objects in the unit test
>> > code (my test data), and mock out ISession and have it return that
>> > test data when .Linq<T> is called on the session.  To do that I've
>> > started creating my own test stub that implements IQueryable that
>> > would be responsible for returning the test data, but I'm having
>> > trouble making that work.
>>
>> > So, just wondering if anyone could suggest a better path to accomplish
>> > this?  Or am I on the correct path?
>>
>> > Thanks!
>> > Troy
>
>
>
>
>
> >
>



-- 
Stefan Sedich
Software Developer
http://weblogs.asp.net/stefansedich

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to