< Summary

Information
Class: Elsa.Persistence.EFCore.Modules.Alterations.EFCoreAlterationJobStore
Assembly: Elsa.Persistence.EFCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Alterations/AlterationJobStore.cs
Line coverage
13%
Covered lines: 3
Uncovered lines: 20
Coverable lines: 23
Total lines: 79
Line coverage: 13%
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%11100%
SaveAsync()100%210%
SaveManyAsync()100%210%
FindAsync()100%210%
FindManyAsync()100%210%
FindManyIdsAsync()100%210%
CountAsync()100%210%
OnSaveAsync(...)100%210%
OnLoadAsync(...)0%620%
Filter(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Alterations/AlterationJobStore.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Alterations.Core.Contracts;
 3using Elsa.Alterations.Core.Entities;
 4using Elsa.Alterations.Core.Filters;
 5using Elsa.Alterations.Core.Models;
 6using Open.Linq.AsyncExtensions;
 7
 8namespace Elsa.Persistence.EFCore.Modules.Alterations;
 9
 10/// <summary>
 11/// An EF Core implementation of <see cref="IAlterationPlanStore"/>.
 12/// </summary>
 13public class EFCoreAlterationJobStore : IAlterationJobStore
 14{
 15    private readonly EntityStore<AlterationsElsaDbContext, AlterationJob> _store;
 16
 17    /// <summary>
 18    /// Constructor.
 19    /// </summary>
 32020    public EFCoreAlterationJobStore(EntityStore<AlterationsElsaDbContext, AlterationJob> store)
 21    {
 32022        _store = store;
 32023    }
 24
 25    /// <inheritdoc />
 26    public async Task SaveAsync(AlterationJob record, CancellationToken cancellationToken = default)
 27    {
 028        await _store.SaveAsync(record, OnSaveAsync, cancellationToken);
 029    }
 30
 31    /// <inheritdoc />
 32    public async Task SaveManyAsync(IEnumerable<AlterationJob> jobs, CancellationToken cancellationToken = default)
 33    {
 034        await _store.SaveManyAsync(jobs, OnSaveAsync, cancellationToken);
 035    }
 36
 37    /// <inheritdoc />
 38    public async Task<AlterationJob?> FindAsync(AlterationJobFilter filter, CancellationToken cancellationToken = defaul
 39    {
 040        return await _store.FindAsync(filter.Apply, OnLoadAsync, cancellationToken);
 041    }
 42
 43    /// <inheritdoc />
 44    public async Task<IEnumerable<AlterationJob>> FindManyAsync(AlterationJobFilter filter, CancellationToken cancellati
 45    {
 046        return await _store.QueryAsync(filter.Apply, OnLoadAsync, cancellationToken).ToList();
 047    }
 48
 49    /// <inheritdoc />
 50    public async Task<IEnumerable<string>> FindManyIdsAsync(AlterationJobFilter filter, CancellationToken cancellationTo
 51    {
 052        return await _store.QueryAsync(filter.Apply, x => x.Id, cancellationToken);
 053    }
 54
 55    /// <inheritdoc />
 56    public async Task<long> CountAsync(AlterationJobFilter filter, CancellationToken cancellationToken = default)
 57    {
 058        return await _store.CountAsync(queryable => Filter(queryable, filter), cancellationToken);
 059    }
 60
 61    private static ValueTask OnSaveAsync(AlterationsElsaDbContext elsaDbContext, AlterationJob entity, CancellationToken
 62    {
 063        elsaDbContext.Entry(entity).Property("SerializedLog").CurrentValue = JsonSerializer.Serialize(entity.Log);
 064        return default;
 65    }
 66
 67    private static ValueTask OnLoadAsync(AlterationsElsaDbContext elsaDbContext, AlterationJob? entity, CancellationToke
 68    {
 069        if (entity is null)
 070            return default;
 71
 072        var logJson = elsaDbContext.Entry(entity).Property<string>("SerializedLog").CurrentValue;
 073        entity.Log = JsonSerializer.Deserialize<AlterationLogEntry[]>(logJson)!;
 74
 075        return default;
 76    }
 77
 078    private static IQueryable<AlterationJob> Filter(IQueryable<AlterationJob> queryable, AlterationJobFilter filter) => 
 79}