< Summary

Information
Class: Elsa.Workflows.Runtime.Stores.MemoryTriggerStore
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Stores/MemoryTriggerStore.cs
Line coverage
47%
Covered lines: 10
Uncovered lines: 11
Coverable lines: 21
Total lines: 80
Line coverage: 47.6%
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%11100%
SaveManyAsync(...)100%210%
FindAsync(...)100%210%
FindManyAsync(...)100%11100%
FindManyAsync(...)100%210%
FindManyAsync(...)100%210%
ReplaceAsync(...)100%11100%
DeleteManyAsync()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Stores/MemoryTriggerStore.cs

#LineLine coverage
 1using Elsa.Common.Entities;
 2using Elsa.Common.Models;
 3using Elsa.Common.Services;
 4using Elsa.Extensions;
 5using Elsa.Workflows.Runtime.Entities;
 6using Elsa.Workflows.Runtime.Filters;
 7using Elsa.Workflows.Runtime.OrderDefinitions;
 8using JetBrains.Annotations;
 9
 10namespace Elsa.Workflows.Runtime.Stores;
 11
 12/// <inheritdoc />
 13[UsedImplicitly]
 14public class MemoryTriggerStore : ITriggerStore
 15{
 16    private readonly MemoryStore<StoredTrigger> _store;
 17
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="MemoryTriggerStore"/> class.
 20    /// </summary>
 15821    public MemoryTriggerStore(MemoryStore<StoredTrigger> store)
 22    {
 15823        _store = store;
 15824    }
 25
 26    /// <inheritdoc />
 27    public ValueTask SaveAsync(StoredTrigger record, CancellationToken cancellationToken = default)
 28    {
 1229        _store.Save(record, x => x.Id);
 630        return new();
 31    }
 32
 33    /// <inheritdoc />
 34    public ValueTask SaveManyAsync(IEnumerable<StoredTrigger> records, CancellationToken cancellationToken = default)
 35    {
 036        _store.SaveMany(records, x => x.Id);
 037        return new();
 38    }
 39
 40    /// <inheritdoc />
 41    public ValueTask<StoredTrigger?> FindAsync(TriggerFilter filter, CancellationToken cancellationToken = default)
 42    {
 043        var entity = _store.Query(filter.Apply).FirstOrDefault();
 044        return new(entity);
 45    }
 46
 47    /// <inheritdoc />
 48    public ValueTask<IEnumerable<StoredTrigger>> FindManyAsync(TriggerFilter filter, CancellationToken cancellationToken
 49    {
 16550        var entities = _store.Query(filter.Apply);
 16551        return new(entities);
 52    }
 53
 54    public ValueTask<Page<StoredTrigger>> FindManyAsync(TriggerFilter filter, PageArgs pageArgs, CancellationToken cance
 55    {
 056        return FindManyAsync(filter, pageArgs, new StoredTriggerOrder<string>(x => x.Id, OrderDirection.Ascending), canc
 57    }
 58
 59    public ValueTask<Page<StoredTrigger>> FindManyAsync<TOrderBy>(TriggerFilter filter, PageArgs pageArgs, StoredTrigger
 60    {
 061        var count = _store.Query(filter.Apply).LongCount();
 062        var result = _store.Query(query => filter.Apply(query).OrderBy(order).Paginate(pageArgs)).ToList();
 063        return ValueTask.FromResult(Page.Of(result, count));
 64    }
 65
 66    /// <inheritdoc />
 67    public ValueTask ReplaceAsync(IEnumerable<StoredTrigger> removed, IEnumerable<StoredTrigger> added, CancellationToke
 68    {
 15569        _store.DeleteMany(removed, x => x.Id);
 15870        _store.SaveMany(added, x => x.Id);
 15271        return new();
 72    }
 73
 74    /// <inheritdoc />
 75    public async ValueTask<long> DeleteManyAsync(TriggerFilter filter, CancellationToken cancellationToken = default)
 76    {
 077        var ids = (await FindManyAsync(filter, cancellationToken)).Select(x => x.Id);
 078        return _store.DeleteMany(ids);
 079    }
 80}