Tuesday, 3 September 2013

Mock Dependency Injection repository with filter

Mock Dependency Injection repository with filter

trying to mock repository :
var expMock = new Mock<IEntityRepository>();
expMock.Setup(s => s.GetMany(It.IsAny<Expression<Func<Entity, bool>>>()))
.Returns<IQueryable<Entity>>(r =>
new List<Entity>{ new Entity() }
}.AsQueryable());
but when i call it:
IEnumerable<Entity> source = _entityRepository.GetMany(w => w.IsActive);
i get an exception:
System.ArgumentException : Object of type
'System.Linq.Expressions.Expression`1[System.Func`2[Entity,System.Boolean]]'
cannot be converted to type 'System.Linq.IQueryable`1[Entity]'.

No comments:

Post a Comment