< Summary

Information
Class: Elsa.Workflows.Runtime.Stores.MemoryBookmarkStore
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Stores/MemoryBookmarkStore.cs
Line coverage
88%
Covered lines: 15
Uncovered lines: 2
Coverable lines: 17
Total lines: 66
Line coverage: 88.2%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
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%11100%
FindManyAsync(...)100%11100%
FindManyAsync(...)100%11100%
DeleteAsync()100%11100%
Filter(...)100%11100%
get_CurrentTenantId()100%44100%

File(s)

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

#LineLine coverage
 1using Elsa.Common.Models;
 2using Elsa.Common.Multitenancy;
 3using Elsa.Common.Services;
 4using Elsa.Extensions;
 5using Elsa.Workflows.Runtime.Entities;
 6using Elsa.Workflows.Runtime.Filters;
 7using JetBrains.Annotations;
 8
 9namespace Elsa.Workflows.Runtime.Stores;
 10
 11/// <inheritdoc />
 12[UsedImplicitly]
 49913public class MemoryBookmarkStore(MemoryStore<StoredBookmark> store, ITenantAccessor? tenantAccessor = null) : IBookmarkS
 14{
 15    /// <inheritdoc />
 16    public ValueTask SaveAsync(StoredBookmark record, CancellationToken cancellationToken = default)
 17    {
 14418        store.Save(record, x => x.Id);
 7219        return ValueTask.CompletedTask;
 20    }
 21
 22    /// <inheritdoc />
 23    public ValueTask SaveManyAsync(IEnumerable<StoredBookmark> records, CancellationToken cancellationToken)
 24    {
 025        store.SaveMany(records, x => x.Id);
 026        return ValueTask.CompletedTask;
 27    }
 28
 29    /// <inheritdoc />
 30    public ValueTask<StoredBookmark?> FindAsync(BookmarkFilter filter, CancellationToken cancellationToken = default)
 31    {
 1232        var entity = store.Query(query => Filter(query, filter)).FirstOrDefault();
 633        return new(entity);
 34    }
 35
 36    /// <inheritdoc />
 37    public ValueTask<IEnumerable<StoredBookmark>> FindManyAsync(BookmarkFilter filter, CancellationToken cancellationTok
 38    {
 18239        var entities = store.Query(query => Filter(query, filter)).AsEnumerable();
 9140        return new(entities);
 41    }
 42
 43    /// <inheritdoc />
 44    public ValueTask<Page<StoredBookmark>> FindManyAsync(BookmarkFilter filter, PageArgs pageArgs, CancellationToken can
 45    {
 16046        var count = store.Query(query => Filter(query, filter)).LongCount();
 16047        var result = store.Query(query => Filter(query, filter).OrderBy(x => x.Id).Paginate(pageArgs)).ToList();
 8048        return new(Page.Of(result, count));
 49    }
 50
 51    /// <inheritdoc />
 52    public async ValueTask<long> DeleteAsync(BookmarkFilter filter, CancellationToken cancellationToken = default)
 53    {
 5454        var ids = (await FindManyAsync(filter, cancellationToken)).Select(x => x.Id);
 2455        return store.DeleteMany(ids);
 2456    }
 57
 58    /// <remarks>
 59    /// Ambient tenant is applied here rather than in <see cref="BookmarkFilter.Apply"/>.
 60    /// EF owns that via <c>SetTenantIdFilter</c> / <c>IgnoreQueryFilters</c>; Memory must compensate.
 61    /// </remarks>
 62    private IQueryable<StoredBookmark> Filter(IQueryable<StoredBookmark> query, BookmarkFilter filter) =>
 25763        filter.Apply(query.WhereVisibleToTenant(CurrentTenantId, filter.TenantAgnostic));
 64
 25765    private string CurrentTenantId => tenantAccessor?.TenantId ?? Tenant.DefaultTenantId;
 66}