using System.Linq.Expressions; using PoweredSoft.Data.Core; namespace DigitalOps.Dal; public class InMemoryQueryableHandlerService : IAsyncQueryableHandlerService { public Task AnyAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { return Task.FromResult(queryable.Any(predicate)); } public Task AnyAsync(IQueryable queryable, CancellationToken cancellationToken = default) { return Task.FromResult(queryable.Any()); } public bool CanHandle(IQueryable queryable) { var result = queryable is EnumerableQuery; return result; } public Task CountAsync(IQueryable queryable, CancellationToken cancellationToken = default) { return Task.FromResult(queryable.Count()); } public Task FirstOrDefaultAsync(IQueryable queryable, CancellationToken cancellationToken = default) { return Task.FromResult(queryable.FirstOrDefault()); } public Task FirstOrDefaultAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { return Task.FromResult(queryable.FirstOrDefault(predicate)); } public Task LongCountAsync(IQueryable queryable, CancellationToken cancellationToken = default) { return Task.FromResult(queryable.LongCount()); } public Task> ToListAsync(IQueryable queryable, CancellationToken cancellationToken = default) { return Task.FromResult(queryable.ToList()); } }