Both actually. I specifically want to test querying logic like this:
public Customer FindByCustomerNumber(string customerNumber)
{
return _repository.FindBy<Customer>(b => b.CustomerNumber ==
customerNumber);
}
Which calls....
public T FindBy<T>(Expression<Func<T, bool>> where)
{
return Session.Linq<T>().Where(where).FirstOrDefault();
}
None of that code has any database concerns, just querying, so I would like
to test it by mocking away the DB / NH Session.
For integration testing, we would like to use the PersistenceSpecification
utility...
new PersistenceSpecification<Customer>(Session)
.CheckProperty(x => x.FirstName, "Dude")
.VerifyTheMappings();
Does that make sense? With Linq to NH, it seems like we should be able to
test our querying logic without doing heavy and messy integration work.
Thanks!
Troy
On Thu, Jan 15, 2009 at 2:22 PM, John Teague <[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]> 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
>>
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---