Mario Guadanhim Mario Guadanhim - 5 months ago 46
C# Question

Mocking Generic Repository unit test

I'm creating a unit test and i'm using rhino mocks (i've never worked with any kind of mocks before, (if you guys know how to handle it with another mock framework, please show me some examples with them)).

In my scenario i'm trying to mock the following generic repository

public interface Repository
IEnumerable<TEntity> Search(Expression<Func<TEntity, bool>> filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> order = null);

My unit test:

_classRepository.Stub(x => x.Search(myclass => == 1 &&

the array class has only one register with id 1.

When i run my test i receive the following message:

Value cannot be null.
Parameter name: source


I solved my problem when changed my mock framework to Moq. So i could use the lambda expressions on my mock setup.

_myclassRepository.Setup(x => x.Search(
          myclass => == 1,
          It.IsAny<Func<IQueryable<MyClass>, IOrderedQueryable<MyClass>>>(),