< Summary

Information
Class: Elsa.Persistence.EFCore.Modules.Identity.EFCoreRoleStore
Assembly: Elsa.Persistence.EFCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Identity/RoleStore.cs
Line coverage
18%
Covered lines: 3
Uncovered lines: 13
Coverable lines: 16
Total lines: 65
Line coverage: 18.7%
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%11100%
SaveAsync()100%210%
AddAsync()100%210%
DeleteAsync()100%210%
TryDeleteAsync()100%210%
FindAsync()100%210%
FindManyAsync()100%210%
Filter(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Identity/RoleStore.cs

#LineLine coverage
 1using Elsa.Identity.Contracts;
 2using Elsa.Identity.Entities;
 3using Elsa.Identity.Models;
 4using Open.Linq.AsyncExtensions;
 5
 6namespace Elsa.Persistence.EFCore.Modules.Identity;
 7
 8/// <summary>
 9/// An EF Core implementation of <see cref="IRoleStore"/>.
 10/// </summary>
 11public class EFCoreRoleStore : IRoleStore, IRoleStoreWithAtomicDelete
 12{
 13    private readonly EntityStore<IdentityElsaDbContext, Role> _applicationStore;
 14
 15    /// <summary>
 16    /// Initializes a new instance of <see cref="EFCoreRoleStore"/>.
 17    /// </summary>
 318    public EFCoreRoleStore(EntityStore<IdentityElsaDbContext, Role> applicationStore)
 19    {
 320        _applicationStore = applicationStore;
 321    }
 22
 23    /// <inheritdoc />
 24    public async Task SaveAsync(Role application, CancellationToken cancellationToken = default)
 25    {
 026        await _applicationStore.SaveAsync(application, cancellationToken);
 027    }
 28
 29    /// <inheritdoc />
 30    public async Task AddAsync(Role role, CancellationToken cancellationToken = default)
 31    {
 032        await _applicationStore.AddAsync(role, cancellationToken);
 033    }
 34
 35    /// <inheritdoc />
 36    public async Task DeleteAsync(RoleFilter filter, CancellationToken cancellationToken = default)
 37    {
 038        await _applicationStore.DeleteWhereAsync(query => Filter(query, filter), cancellationToken);
 039    }
 40
 41    /// <inheritdoc />
 42    /// <remarks>
 43    /// The delete is issued as a single <c>DELETE ... WHERE</c> statement and the affected-row count it returns is
 44    /// the database's own verdict on which caller removed the row, so two concurrent callers cannot both observe
 45    /// <see langword="true"/>.
 46    /// </remarks>
 47    public async Task<bool> TryDeleteAsync(string roleId, CancellationToken cancellationToken = default)
 48    {
 049        return await _applicationStore.DeleteWhereAsync(query => Filter(query, new RoleFilter { Id = roleId }), cancella
 050    }
 51
 52    /// <inheritdoc />
 53    public async Task<Role?> FindAsync(RoleFilter filter, CancellationToken cancellationToken = default)
 54    {
 055        return await _applicationStore.FindAsync(query => Filter(query, filter), cancellationToken);
 056    }
 57
 58    /// <inheritdoc />
 59    public async Task<IEnumerable<Role>> FindManyAsync(RoleFilter filter, CancellationToken cancellationToken = default)
 60    {
 061        return await _applicationStore.QueryAsync(queryable => Filter(queryable, filter), cancellationToken).ToList();
 062    }
 63
 064    private static IQueryable<Role> Filter(IQueryable<Role> query, RoleFilter filter) => filter.Apply(query);
 65}