< Summary

Information
Class: Elsa.Identity.Services.MemoryRoleStore
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/MemoryRoleStore.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 60
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%
AddAsync(...)100%210%
DeleteAsync(...)100%210%
SaveAsync(...)100%210%
FindAsync(...)100%210%
FindManyAsync(...)100%210%
Filter(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/MemoryRoleStore.cs

#LineLine coverage
 1using Elsa.Common.Services;
 2using Elsa.Identity.Contracts;
 3using Elsa.Identity.Entities;
 4using Elsa.Identity.Models;
 5
 6namespace Elsa.Identity.Services;
 7
 8/// <summary>
 9/// Represents an in-memory role store.
 10/// </summary>
 11public class MemoryRoleStore : IRoleStore
 12{
 13    private readonly MemoryStore<Role> _store;
 14
 15    /// <summary>
 16    /// Initializes a new instance of the <see cref="MemoryRoleStore"/> class.
 17    /// </summary>
 018    public MemoryRoleStore(MemoryStore<Role> store)
 19    {
 020        _store = store;
 021    }
 22
 23    /// <inheritdoc />
 24    public Task AddAsync(Role role, CancellationToken cancellationToken = default)
 25    {
 026        _store.Save(role, x => x.Id);
 027        return Task.CompletedTask;
 28    }
 29
 30    /// <inheritdoc />
 31    public Task DeleteAsync(RoleFilter filter, CancellationToken cancellationToken = default)
 32    {
 033        var ids = _store.Query(query => Filter(query, filter)).Select(x => x.Id).Distinct().ToList();
 034        _store.DeleteWhere(x => ids.Contains(x.Id));
 035        return Task.CompletedTask;
 36    }
 37
 38    /// <inheritdoc />
 39    public Task SaveAsync(Role role, CancellationToken cancellationToken = default)
 40    {
 041        _store.Save(role, x => x.Id);
 042        return Task.CompletedTask;
 43    }
 44
 45    /// <inheritdoc />
 46    public Task<Role?> FindAsync(RoleFilter filter, CancellationToken cancellationToken = default)
 47    {
 048        var result = _store.Query(query => Filter(query, filter)).FirstOrDefault();
 049        return Task.FromResult(result);
 50    }
 51
 52    /// <inheritdoc />
 53    public Task<IEnumerable<Role>> FindManyAsync(RoleFilter filter, CancellationToken cancellationToken = default)
 54    {
 055        var result = _store.Query(query => Filter(query, filter)).ToList().AsEnumerable();
 056        return Task.FromResult(result);
 57    }
 58
 059    private IQueryable<Role> Filter(IQueryable<Role> queryable, RoleFilter filter) => filter.Apply(queryable);
 60}