romantitov / MockQueryable

Mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc
MIT License
791 stars 77 forks source link

Queryable filters are not applied to inmemory datasets #78

Closed d1820 closed 4 months ago

d1820 commented 4 months ago

I create a mockObject and when i apply the where condition with a FirstOrDefaultAsync is does not actually filter the data.

var data = new List<MyItem>{
new MyItem {Id = {guid},
new MyItem {Id = {guid2},
}.BuildMock();

 _myRepo.Setup(f => f.GetAsNoTracking(It.IsAny<Expression<Func<MyItem, bool>>>(), null, "")).Returns(() => data);

result = _myRepo.GetAsNoTracking(f => f.Id == {guid2}) .FirstOrDefaultAsync();

function GetAsNoTracking(Expression<Func<TEntity, bool>>? filter = null){
IQueryable<TEntity> query = _dbSet;

if (asNoTracking)
{
    query = query.AsNoTracking();
}

if (filter != null)
{
    query = query.Where(filter);
}
}

Am i missing how this works? My understanding was it will actually filter the in-memory data sets