< Summary

Information
Class: Elsa.Tenants.MemoryTenantStore
Assembly: Elsa.Tenants
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Services/MemoryTenantStore.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 61
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
FindAsync(...)100%210%
FindAsync(...)100%210%
FindManyAsync(...)100%210%
ListAsync(...)100%210%
AddAsync(...)100%210%
UpdateAsync(...)100%210%
DeleteAsync(...)100%210%
DeleteAsync(...)100%210%
Filter(...)100%210%
GetId(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Services/MemoryTenantStore.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Common.Services;
 3using JetBrains.Annotations;
 4
 5namespace Elsa.Tenants;
 6
 7[UsedImplicitly]
 08public class MemoryTenantStore(MemoryStore<Tenant> store) : ITenantStore
 9{
 10    public Task<Tenant?> FindAsync(TenantFilter filter, CancellationToken cancellationToken = default)
 11    {
 012        var result = store.Query(query => Filter(query, filter)).FirstOrDefault();
 013        return Task.FromResult(result);
 14    }
 15
 16    public Task<Tenant?> FindAsync(string id, CancellationToken cancellationToken = default)
 17    {
 018        var filter = TenantFilter.ById(id);
 019        return FindAsync(filter, cancellationToken);
 20    }
 21
 22    public Task<IEnumerable<Tenant>> FindManyAsync(TenantFilter filter, CancellationToken cancellationToken = default)
 23    {
 024        var result = store.Query(query => Filter(query, filter)).ToList().AsEnumerable();
 025        return Task.FromResult(result);
 26    }
 27
 28    public Task<IEnumerable<Tenant>> ListAsync(CancellationToken cancellationToken = default)
 29    {
 030        var result = store.List();
 031        return Task.FromResult(result);
 32    }
 33
 34    public Task AddAsync(Tenant tenant, CancellationToken cancellationToken = default)
 35    {
 036        store.Add(tenant, GetId);
 037        return Task.CompletedTask;
 38    }
 39
 40    public Task UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default)
 41    {
 042        store.Update(tenant, GetId);
 043        return Task.CompletedTask;
 44    }
 45
 46    public Task<bool> DeleteAsync(string id, CancellationToken cancellationToken = default)
 47    {
 048        var found = store.Delete(id);
 049        return Task.FromResult(found);
 50    }
 51
 52    public Task<long> DeleteAsync(TenantFilter filter, CancellationToken cancellationToken = default)
 53    {
 054        var deletedCount = store.DeleteMany(filter.Apply(store.Queryable), GetId);
 055        return Task.FromResult(deletedCount);
 56    }
 57
 058    private IQueryable<Tenant> Filter(IQueryable<Tenant> queryable, TenantFilter filter) => filter.Apply(queryable);
 59
 060    private string GetId(Tenant tenant) => tenant.Id;
 61}