< Summary

Information
Class: Elsa.Persistence.EFCore.Modules.Runtime.EFCoreBookmarkStore
Assembly: Elsa.Persistence.EFCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Runtime/BookmarkStore.cs
Line coverage
80%
Covered lines: 20
Uncovered lines: 5
Coverable lines: 25
Total lines: 74
Line coverage: 80%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
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%11100%
DeleteAsync()100%11100%
OnSaveAsync(...)75%44100%
OnLoadAsync(...)66.66%6685.71%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Runtime/BookmarkStore.cs

#LineLine coverage
 1using Elsa.Common.Models;
 2using Elsa.Extensions;
 3using Elsa.Workflows;
 4using Elsa.Workflows.Runtime;
 5using Elsa.Workflows.Runtime.Entities;
 6using Elsa.Workflows.Runtime.Filters;
 7using JetBrains.Annotations;
 8
 9namespace Elsa.Persistence.EFCore.Modules.Runtime;
 10
 11/// <summary>
 12/// An EF Core implementation of <see cref="IBookmarkStore"/>.
 13/// </summary>
 14[UsedImplicitly]
 61315public class EFCoreBookmarkStore(Store<RuntimeElsaDbContext, StoredBookmark> store, IPayloadSerializer serializer) : IBo
 16{
 17    /// <inheritdoc />
 18    public async ValueTask SaveAsync(StoredBookmark record, CancellationToken cancellationToken = default)
 19    {
 3920        await store.SaveAsync(record, s => s.Id, OnSaveAsync, cancellationToken);
 3921    }
 22
 23    /// <inheritdoc />
 24    public async ValueTask SaveManyAsync(IEnumerable<StoredBookmark> records, CancellationToken cancellationToken)
 25    {
 026        await store.SaveManyAsync(records, s => s.Id, OnSaveAsync, cancellationToken);
 027    }
 28
 29    /// <inheritdoc />
 30    public async ValueTask<StoredBookmark?> FindAsync(BookmarkFilter filter, CancellationToken cancellationToken = defau
 31    {
 032        return await store.FindAsync(filter.Apply, OnLoadAsync, filter.TenantAgnostic, cancellationToken);
 033    }
 34
 35    /// <inheritdoc />
 36    public async ValueTask<IEnumerable<StoredBookmark>> FindManyAsync(BookmarkFilter filter, CancellationToken cancellat
 37    {
 652238        return await store.QueryAsync(filter.Apply, OnLoadAsync, filter.TenantAgnostic, cancellationToken);
 652239    }
 40
 41    /// <inheritdoc />
 42    public async ValueTask<Page<StoredBookmark>> FindManyAsync(BookmarkFilter filter, PageArgs pageArgs, CancellationTok
 43    {
 1244        var count = await store.CountAsync(filter.Apply, filter.TenantAgnostic, cancellationToken);
 2445        var results = (await store.QueryAsync(query => filter.Apply(query).OrderBy(x => x.Id).Paginate(pageArgs), OnLoad
 1246        return Page.Of(results, count);
 1247    }
 48
 49    /// <inheritdoc />
 50    public async ValueTask<long> DeleteAsync(BookmarkFilter filter, CancellationToken cancellationToken = default)
 51    {
 4052        return await store.DeleteWhereAsync(filter.Apply, cancellationToken);
 4053    }
 54
 55    private ValueTask OnSaveAsync(RuntimeElsaDbContext dbContext, StoredBookmark entity, CancellationToken cancellationT
 56    {
 3957        dbContext.Entry(entity).Property("SerializedPayload").CurrentValue = entity.Payload != null ? serializer.Seriali
 3958        dbContext.Entry(entity).Property("SerializedMetadata").CurrentValue = entity.Metadata != null ? serializer.Seria
 3959        return default;
 60    }
 61
 62    private ValueTask OnLoadAsync(RuntimeElsaDbContext dbContext, StoredBookmark? entity, CancellationToken cancellation
 63    {
 7164        if (entity is null)
 065            return default;
 66
 7167        var payloadJson = dbContext.Entry(entity).Property<string>("SerializedPayload").CurrentValue;
 7168        var metadataJson = dbContext.Entry(entity).Property<string>("SerializedMetadata").CurrentValue;
 7169        entity.Payload = !string.IsNullOrEmpty(payloadJson) ? serializer.Deserialize(payloadJson) : null;
 7170        entity.Metadata = !string.IsNullOrEmpty(metadataJson) ? serializer.Deserialize<Dictionary<string, string>>(metad
 71
 7172        return default;
 73    }
 74}