< Summary

Information
Class: Elsa.Persistence.EFCore.Modules.Runtime.EFCoreWorkflowExecutionLogStore
Assembly: Elsa.Persistence.EFCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Runtime/WorkflowExecutionLogStore.cs
Line coverage
60%
Covered lines: 23
Uncovered lines: 15
Coverable lines: 38
Total lines: 106
Line coverage: 60.5%
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%
AddAsync()100%210%
AddManyAsync()100%11100%
SaveAsync()100%210%
SaveManyAsync()100%210%
FindAsync()100%210%
FindAsync()100%210%
FindManyAsync()100%11100%
FindManyAsync()100%210%
DeleteManyAsync()100%11100%
OnSaveAsync(...)100%22100%
OnLoadAsync()50%2275%
LoadPayload(...)50%22100%
ShouldSerializePayload(...)75%4483.33%
Filter(...)100%11100%

File(s)

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

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Common.Models;
 3using Elsa.Extensions;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Runtime;
 6using Elsa.Workflows.Runtime.Entities;
 7using Elsa.Workflows.Runtime.Extensions;
 8using Elsa.Workflows.Runtime.Filters;
 9using Elsa.Workflows.Runtime.OrderDefinitions;
 10using Open.Linq.AsyncExtensions;
 11
 12namespace Elsa.Persistence.EFCore.Modules.Runtime;
 13
 14/// <summary>
 15/// An EF Core implementation of <see cref="IWorkflowExecutionLogStore"/>.
 16/// </summary>
 32117public class EFCoreWorkflowExecutionLogStore(EntityStore<RuntimeElsaDbContext, WorkflowExecutionLogRecord> store, ISafeS
 18{
 19    /// <inheritdoc />
 020    public async Task AddAsync(WorkflowExecutionLogRecord record, CancellationToken cancellationToken = default) => awai
 21
 22    /// <inheritdoc />
 23    public async Task AddManyAsync(IEnumerable<WorkflowExecutionLogRecord> records, CancellationToken cancellationToken 
 24    {
 32325        await store.AddManyAsync(records, OnSaveAsync, cancellationToken);
 32326    }
 27
 28    /// <inheritdoc />
 29    public async Task SaveAsync(WorkflowExecutionLogRecord record, CancellationToken cancellationToken = default)
 30    {
 031        await store.SaveAsync(record, OnSaveAsync, cancellationToken);
 032    }
 33
 34    /// <inheritdoc />
 35    public async Task SaveManyAsync(IEnumerable<WorkflowExecutionLogRecord> records, CancellationToken cancellationToken
 36    {
 037        await store.SaveManyAsync(records, OnSaveAsync, cancellationToken);
 038    }
 39
 40    /// <inheritdoc />
 41    public async Task<WorkflowExecutionLogRecord?> FindAsync(WorkflowExecutionLogRecordFilter filter, CancellationToken 
 42    {
 043        return await store.QueryAsync(queryable => Filter(queryable, filter), OnLoadAsync, cancellationToken).FirstOrDef
 044    }
 45
 46    /// <inheritdoc />
 47    public async Task<WorkflowExecutionLogRecord?> FindAsync<TOrderBy>(WorkflowExecutionLogRecordFilter filter, Workflow
 48    {
 049        return await store.QueryAsync(queryable => Filter(queryable, filter).OrderBy(order), OnLoadAsync, cancellationTo
 050    }
 51
 52    /// <inheritdoc />
 53    public async Task<Page<WorkflowExecutionLogRecord>> FindManyAsync(WorkflowExecutionLogRecordFilter filter, PageArgs 
 54    {
 1655        var count = await store.QueryAsync(queryable => Filter(queryable, filter), cancellationToken).LongCount();
 1656        var results = await store.QueryAsync(queryable => Filter(queryable, filter).OrderBy(x => x.Timestamp).Paginate(p
 857        return new(results, count);
 858    }
 59
 60    /// <inheritdoc />
 61    public async Task<Page<WorkflowExecutionLogRecord>> FindManyAsync<TOrderBy>(WorkflowExecutionLogRecordFilter filter,
 62    {
 063        var count = await store.QueryAsync(queryable => Filter(queryable, filter), cancellationToken).LongCount();
 064        var results = await store.QueryAsync(queryable => Filter(queryable, filter).OrderBy(order).Paginate(pageArgs), O
 065        return new(results, count);
 066    }
 67
 68    /// <inheritdoc />
 69    public async Task<long> DeleteManyAsync(WorkflowExecutionLogRecordFilter filter, CancellationToken cancellationToken
 70    {
 2671        return await store.DeleteWhereAsync(queryable => Filter(queryable, filter), cancellationToken);
 1372    }
 73
 74    private ValueTask OnSaveAsync(RuntimeElsaDbContext dbContext, WorkflowExecutionLogRecord entity, CancellationToken c
 75    {
 476976        entity = entity.SanitizeLogMessage();
 476977        dbContext.Entry(entity).Property("SerializedPayload").CurrentValue = ShouldSerializePayload(entity) ? safeSerial
 476978        return ValueTask.CompletedTask;
 79    }
 80
 81    private async ValueTask OnLoadAsync(RuntimeElsaDbContext dbContext, WorkflowExecutionLogRecord? entity, Cancellation
 82    {
 3283        if (entity is null)
 084            return;
 85
 3286        entity.Payload = await LoadPayload(dbContext, entity);
 3287    }
 88
 89    private ValueTask<object?> LoadPayload(RuntimeElsaDbContext dbContext, WorkflowExecutionLogRecord entity)
 90    {
 3291        var json = dbContext.Entry(entity).Property<string>("SerializedPayload").CurrentValue;
 3292        return new(!string.IsNullOrEmpty(json) ? JsonSerializer.Deserialize<object>(json) : null);
 93    }
 94
 95    private bool ShouldSerializePayload(WorkflowExecutionLogRecord source)
 96    {
 476997        return source.Payload switch
 476998        {
 476499            null => false,
 0100            IDictionary<string, object> dictionary => dictionary.Count > 0,
 5101            _ => true
 4769102        };
 103    }
 104
 29105    private static IQueryable<WorkflowExecutionLogRecord> Filter(IQueryable<WorkflowExecutionLogRecord> queryable, Workf
 106}