What you can do is to move the Linq expression from your repository into the business logic and mock the repository instead.
public interface IPersonRepository : IRepository<Person>
{
IQueryable<Person> GetAll { get; }
}
public class PersonRepository : EFRepository<Person>, IPersonRepository
{
// ...
public IQueryable<Person> GetAll
{
get { return DbSet; }
}
}
public class SomeBusinessLogicClass
{
private readonly IPersonRepository _people;
public SomeBusinessLogicClass(IPersonRepository people)
{
_people = people;
}
public IEnumerable<Person> GetByFirstName(string name)
{
return _people.GetAll.Where(p => p.FirstName == name);
}
}
Now rewrite your test to validate the business logic.
[Fact]
public void SomeTest()
{
//arrange
var mockRepository = new Mock<IPersonRepository>();
var mockData = new List<Person>
{
new Person { Name = "Jim", Age = 47 }
};
mockRepository.Setup(x => x.GetAll).Returns(mockData);
var bl = new SomeBusinessLogicClass(mockRepository.Object);
//act
var result = bl.GetByFirstName("Jim");
//assert
//do some assertion
}