< Summary

Information
Class: Elsa.Labels.Services.InMemoryLabelStore
Assembly: Elsa.Labels
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Labels/Services/InMemoryLabelStore.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 78
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%
SaveAsync(...)100%210%
SaveManyAsync(...)100%210%
DeleteAsync(...)100%210%
DeleteManyAsync(...)100%210%
FindByIdAsync(...)100%210%
ListAsync(...)100%210%
FindManyByIdAsync(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Labels/Services/InMemoryLabelStore.cs

#LineLine coverage
 1using Elsa.Common.Models;
 2using Elsa.Common.Services;
 3using Elsa.Extensions;
 4using Elsa.Labels.Contracts;
 5using Elsa.Labels.Entities;
 6
 7namespace Elsa.Labels.Services;
 8
 9/// <summary>
 10/// An in-memory store of labels.
 11/// </summary>
 12public class InMemoryLabelStore : ILabelStore
 13{
 14    private readonly MemoryStore<Label> _labelStore;
 15    private readonly MemoryStore<WorkflowDefinitionLabel> _workflowDefinitionLabelStore;
 16
 17    /// <summary>
 18    /// Constructor.
 19    /// </summary>
 020    public InMemoryLabelStore(MemoryStore<Label> labelStore, MemoryStore<WorkflowDefinitionLabel> workflowDefinitionLabe
 21    {
 022        _labelStore = labelStore;
 023        _workflowDefinitionLabelStore = workflowDefinitionLabelStore;
 024    }
 25
 26    /// <inheritdoc />
 27    public Task SaveAsync(Label record, CancellationToken cancellationToken = default)
 28    {
 029        _labelStore.Save(record, x => x.Id);
 030        return Task.CompletedTask;
 31    }
 32
 33    /// <inheritdoc />
 34    public Task SaveManyAsync(IEnumerable<Label> records, CancellationToken cancellationToken = default)
 35    {
 036        _labelStore.SaveMany(records, x => x.Id);
 037        return Task.CompletedTask;
 38    }
 39
 40    /// <inheritdoc />
 41    public Task<bool> DeleteAsync(string id, CancellationToken cancellationToken = default)
 42    {
 043        _workflowDefinitionLabelStore.DeleteWhere(x => x.LabelId == id);
 044        var result = _labelStore.Delete(id);
 045        return Task.FromResult(result);
 46    }
 47
 48    /// <inheritdoc />
 49    public Task<long> DeleteManyAsync(IEnumerable<string> ids, CancellationToken cancellationToken = default)
 50    {
 051        var idList = ids.ToList();
 052        _workflowDefinitionLabelStore.DeleteWhere(x => idList.Contains(x.LabelId));
 053        var result = _labelStore.DeleteMany(idList);
 054        return Task.FromResult(result);
 55    }
 56
 57    /// <inheritdoc />
 58    public Task<Label?> FindByIdAsync(string id, CancellationToken cancellationToken = default)
 59    {
 060        var record = _labelStore.Find(x => x.Id == id);
 061        return Task.FromResult(record);
 62    }
 63
 64    /// <inheritdoc />
 65    public Task<Page<Label>> ListAsync(PageArgs? pageArgs = default, CancellationToken cancellationToken = default)
 66    {
 067        var query = _labelStore.List().AsQueryable().OrderBy(x => x.Name);
 068        var page = query.ToPage(pageArgs);
 069        return Task.FromResult(page);
 70    }
 71
 72    /// <inheritdoc />
 73    public Task<IEnumerable<Label>> FindManyByIdAsync(IEnumerable<string> ids, CancellationToken cancellationToken)
 74    {
 075        var idList = ids.ToList();
 076        return Task.FromResult(_labelStore.FindMany(x => idList.Contains(x.Id)));
 77    }
 78}