< Summary

Information
Class: Elsa.Workflows.Management.Stores.MemoryWorkflowInstanceStore
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Stores/MemoryWorkflowInstanceStore.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 62
Coverable lines: 62
Total lines: 175
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
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%
FindManyAsync(...)100%210%
FindManyAsync(...)100%210%
FindManyAsync(...)100%210%
FindManyAsync(...)100%210%
CountAsync(...)100%210%
SummarizeManyAsync()100%210%
SummarizeManyAsync()100%210%
SummarizeManyAsync()100%210%
SummarizeManyAsync()100%210%
FindManyIdsAsync(...)100%210%
FindManyIdsAsync()100%210%
FindManyIdsAsync()0%620%
SaveAsync(...)100%210%
AddAsync(...)100%210%
UpdateAsync(...)100%210%
SaveManyAsync(...)100%210%
DeleteAsync(...)100%210%
UpdateUpdatedTimestampAsync()0%620%
GetId(...)100%210%
Filter(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Stores/MemoryWorkflowInstanceStore.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using Elsa.Common.Models;
 3using Elsa.Common.Services;
 4using Elsa.Extensions;
 5using Elsa.Workflows.Management.Entities;
 6using Elsa.Workflows.Management.Filters;
 7using Elsa.Workflows.Management.Models;
 8
 9namespace Elsa.Workflows.Management.Stores;
 10
 11/// <summary>
 12/// A non-persistent memory store for saving and loading <see cref="WorkflowInstance"/> entities.
 13/// </summary>
 14public class MemoryWorkflowInstanceStore : IWorkflowInstanceStore
 15{
 16    private readonly MemoryStore<WorkflowInstance> _store;
 17
 18    /// <summary>
 19    /// Constructor.
 20    /// </summary>
 021    public MemoryWorkflowInstanceStore(MemoryStore<WorkflowInstance> store)
 22    {
 023        _store = store;
 024    }
 25
 26    /// <inheritdoc />
 27    public ValueTask<WorkflowInstance?> FindAsync(WorkflowInstanceFilter filter, CancellationToken cancellationToken = d
 28    {
 029        var entity = _store.Query(query => Filter(query, filter)).FirstOrDefault();
 030        return ValueTask.FromResult(entity);
 31    }
 32
 33    /// <inheritdoc />
 34    public ValueTask<Page<WorkflowInstance>> FindManyAsync(WorkflowInstanceFilter filter, PageArgs pageArgs, Cancellatio
 35    {
 036        var count = _store.Query(query => Filter(query, filter)).LongCount();
 037        var entities = _store.Query(query => Filter(query, filter).Paginate(pageArgs)).ToList();
 038        var page = Page.Of(entities, count);
 039        return ValueTask.FromResult(page);
 40    }
 41
 42    /// <inheritdoc />
 43    public ValueTask<Page<WorkflowInstance>> FindManyAsync<TOrderBy>(WorkflowInstanceFilter filter, PageArgs pageArgs, W
 44    {
 045        var count = _store.Query(query => Filter(query, filter)).LongCount();
 046        var entities = _store.Query(query => Filter(query, filter).OrderBy(order).Paginate(pageArgs)).ToList();
 047        var page = Page.Of(entities, count);
 048        return ValueTask.FromResult(page);
 49    }
 50
 51    /// <inheritdoc />
 52    public ValueTask<IEnumerable<WorkflowInstance>> FindManyAsync(WorkflowInstanceFilter filter, CancellationToken cance
 53    {
 054        var entities = _store.Query(query => Filter(query, filter)).ToList().AsEnumerable();
 055        return ValueTask.FromResult(entities);
 56    }
 57
 58    /// <inheritdoc />
 59    public ValueTask<IEnumerable<WorkflowInstance>> FindManyAsync<TOrderBy>(WorkflowInstanceFilter filter, WorkflowInsta
 60    {
 061        var entities = _store.Query(query => Filter(query, filter).OrderBy(order)).ToList().AsEnumerable();
 062        return ValueTask.FromResult(entities);
 63    }
 64
 65    /// <inheritdoc />
 66    public ValueTask<long> CountAsync(WorkflowInstanceFilter filter, CancellationToken cancellationToken = default)
 67    {
 068        var count = _store.Query(query => Filter(query, filter)).LongCount();
 069        return new(count);
 70    }
 71
 72    /// <inheritdoc />
 73    public async ValueTask<Page<WorkflowInstanceSummary>> SummarizeManyAsync(WorkflowInstanceFilter filter, PageArgs pag
 74    {
 075        var page = await FindManyAsync(filter, pageArgs, cancellationToken);
 076        return new(page.Items.Select(WorkflowInstanceSummary.FromInstance).ToList(), page.TotalCount);
 077    }
 78
 79    /// <inheritdoc />
 80    public async ValueTask<Page<WorkflowInstanceSummary>> SummarizeManyAsync<TOrderBy>(WorkflowInstanceFilter filter, Pa
 81    {
 082        var page = await FindManyAsync(filter, pageArgs, order, cancellationToken);
 083        return new(page.Items.Select(WorkflowInstanceSummary.FromInstance).ToList(), page.TotalCount);
 084    }
 85
 86    /// <inheritdoc />
 87    public async ValueTask<IEnumerable<WorkflowInstanceSummary>> SummarizeManyAsync(WorkflowInstanceFilter filter, Cance
 88    {
 089        var entities = await FindManyAsync(filter, cancellationToken);
 090        return entities.Select(WorkflowInstanceSummary.FromInstance);
 091    }
 92
 93    /// <inheritdoc />
 94    public async ValueTask<IEnumerable<WorkflowInstanceSummary>> SummarizeManyAsync<TOrderBy>(WorkflowInstanceFilter fil
 95    {
 096        var entities = await FindManyAsync(filter, order, cancellationToken);
 097        return entities.Select(WorkflowInstanceSummary.FromInstance);
 098    }
 99
 100    /// <inheritdoc />
 101    public ValueTask<IEnumerable<string>> FindManyIdsAsync(WorkflowInstanceFilter filter, CancellationToken cancellation
 102    {
 0103        var entities = _store.Query(query => Filter(query, filter)).Select(x => x.Id).ToList().AsEnumerable();
 0104        return ValueTask.FromResult(entities);
 105    }
 106
 107    /// <inheritdoc />
 108    public async ValueTask<Page<string>> FindManyIdsAsync(WorkflowInstanceFilter filter, PageArgs pageArgs, Cancellation
 109    {
 0110        var page = await FindManyAsync(filter, pageArgs, cancellationToken);
 0111        var ids = page.Items.Select(x => x.Id).ToList();
 0112        return new(ids, page.TotalCount);
 0113    }
 114
 115    /// <inheritdoc />
 116    public async ValueTask<Page<string>> FindManyIdsAsync<TOrderBy>(WorkflowInstanceFilter filter, PageArgs pageArgs, Wo
 117    {
 0118        var page = await FindManyAsync(filter, pageArgs, order, cancellationToken);
 0119        var ids = page.Items.Select(x => x.Id).ToList();
 0120        return new(ids, page.TotalCount);
 0121    }
 122
 123    /// <inheritdoc />
 124    public ValueTask SaveAsync(WorkflowInstance instance, CancellationToken cancellationToken = default)
 125    {
 0126        _store.Save(instance, x => x.Id);
 0127        return ValueTask.CompletedTask;
 128    }
 129
 130    public ValueTask AddAsync(WorkflowInstance instance, CancellationToken cancellationToken = default)
 131    {
 0132        _store.Add(instance, GetId);
 0133        return ValueTask.CompletedTask;
 134    }
 135
 136    public ValueTask UpdateAsync(WorkflowInstance instance, CancellationToken cancellationToken = default)
 137    {
 0138        _store.Update(instance, GetId);
 0139        return ValueTask.CompletedTask;
 140    }
 141
 142    /// <inheritdoc />
 143    public ValueTask SaveManyAsync(IEnumerable<WorkflowInstance> instances, CancellationToken cancellationToken = defaul
 144    {
 0145        _store.SaveMany(instances, GetId);
 0146        return ValueTask.CompletedTask;
 147    }
 148
 149    /// <inheritdoc />
 150    public ValueTask<long> DeleteAsync(WorkflowInstanceFilter filter, CancellationToken cancellationToken = default)
 151    {
 0152        var query = Filter(_store.List().AsQueryable(), filter);
 0153        var count = _store.DeleteMany(query, x => x.Id);
 0154        return ValueTask.FromResult(count);
 155    }
 156
 157    /// <inheritdoc />
 158    public async Task UpdateUpdatedTimestampAsync(string workflowInstanceId, DateTimeOffset value, CancellationToken can
 159    {
 0160        var workflowInstance = await FindAsync(new()
 0161        {
 0162            Id = workflowInstanceId
 0163        }, cancellationToken);
 164
 0165        if (workflowInstance == null)
 0166            throw new InvalidOperationException($"Workflow instance with ID '{workflowInstanceId}' does not exist.");
 167
 0168        workflowInstance.UpdatedAt = value;
 0169    }
 170
 0171    private static string GetId(WorkflowInstance workflowInstance) => workflowInstance.Id;
 172
 173    [RequiresUnreferencedCode("Calls Elsa.Workflows.Management.Filters.WorkflowInstanceFilter.Apply(IQueryable<WorkflowI
 0174    private static IQueryable<WorkflowInstance> Filter(IQueryable<WorkflowInstance> query, WorkflowInstanceFilter filter
 175}

Methods/Properties

.ctor(Elsa.Common.Services.MemoryStore`1<Elsa.Workflows.Management.Entities.WorkflowInstance>)
FindAsync(Elsa.Workflows.Management.Filters.WorkflowInstanceFilter,System.Threading.CancellationToken)
FindManyAsync(Elsa.Workflows.Management.Filters.WorkflowInstanceFilter,Elsa.Common.Models.PageArgs,System.Threading.CancellationToken)
FindManyAsync(Elsa.Workflows.Management.Filters.WorkflowInstanceFilter,Elsa.Common.Models.PageArgs,Elsa.Workflows.Management.Filters.WorkflowInstanceOrder`1<TOrderBy>,System.Threading.CancellationToken)
FindManyAsync(Elsa.Workflows.Management.Filters.WorkflowInstanceFilter,System.Threading.CancellationToken)
FindManyAsync(Elsa.Workflows.Management.Filters.WorkflowInstanceFilter,Elsa.Workflows.Management.Filters.WorkflowInstanceOrder`1<TOrderBy>,System.Threading.CancellationToken)
CountAsync(Elsa.Workflows.Management.Filters.WorkflowInstanceFilter,System.Threading.CancellationToken)
SummarizeManyAsync()
SummarizeManyAsync()
SummarizeManyAsync()
SummarizeManyAsync()
FindManyIdsAsync(Elsa.Workflows.Management.Filters.WorkflowInstanceFilter,System.Threading.CancellationToken)
FindManyIdsAsync()
FindManyIdsAsync()
SaveAsync(Elsa.Workflows.Management.Entities.WorkflowInstance,System.Threading.CancellationToken)
AddAsync(Elsa.Workflows.Management.Entities.WorkflowInstance,System.Threading.CancellationToken)
UpdateAsync(Elsa.Workflows.Management.Entities.WorkflowInstance,System.Threading.CancellationToken)
SaveManyAsync(System.Collections.Generic.IEnumerable`1<Elsa.Workflows.Management.Entities.WorkflowInstance>,System.Threading.CancellationToken)
DeleteAsync(Elsa.Workflows.Management.Filters.WorkflowInstanceFilter,System.Threading.CancellationToken)
UpdateUpdatedTimestampAsync()
GetId(Elsa.Workflows.Management.Entities.WorkflowInstance)
Filter(System.Linq.IQueryable`1<Elsa.Workflows.Management.Entities.WorkflowInstance>,Elsa.Workflows.Management.Filters.WorkflowInstanceFilter)