< Summary

Information
Class: Elsa.Persistence.EFCore.Modules.Alterations.EFCoreAlterationPlanStore
Assembly: Elsa.Persistence.EFCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Alterations/AlterationPlanStore.cs
Line coverage
20%
Covered lines: 4
Uncovered lines: 16
Coverable lines: 20
Total lines: 66
Line coverage: 20%
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%
FindAsync()100%210%
CountAsync()100%210%
OnSaveAsync(...)100%210%
OnLoadAsync(...)0%620%

File(s)

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

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Text.Json;
 3using Elsa.Alterations.Core.Contracts;
 4using Elsa.Alterations.Core.Entities;
 5using Elsa.Alterations.Core.Filters;
 6using Elsa.Alterations.Core.Models;
 7
 8namespace Elsa.Persistence.EFCore.Modules.Alterations;
 9
 10/// <summary>
 11/// An EF Core implementation of <see cref="IAlterationPlanStore"/>.
 12/// </summary>
 13public class EFCoreAlterationPlanStore : IAlterationPlanStore
 14{
 15    private readonly EntityStore<AlterationsElsaDbContext, AlterationPlan> _store;
 16    private readonly IAlterationSerializer _alterationSerializer;
 17
 18    /// <summary>
 19    /// Constructor.
 20    /// </summary>
 32021    public EFCoreAlterationPlanStore(EntityStore<AlterationsElsaDbContext, AlterationPlan> store, IAlterationSerializer 
 22    {
 32023        _store = store;
 32024        _alterationSerializer = alterationSerializer;
 32025    }
 26
 27    /// <inheritdoc />
 28    public async Task SaveAsync(AlterationPlan record, CancellationToken cancellationToken = default)
 29    {
 030        await _store.SaveAsync(record, OnSaveAsync, cancellationToken);
 031    }
 32
 33    /// <inheritdoc />
 34    [RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)"
 35    public async Task<AlterationPlan?> FindAsync(AlterationPlanFilter filter, CancellationToken cancellationToken = defa
 36    {
 037        return await _store.FindAsync(filter.Apply, OnLoadAsync, cancellationToken);
 038    }
 39
 40    /// <inheritdoc />
 41    public async Task<long> CountAsync(AlterationPlanFilter filter, CancellationToken cancellationToken = default)
 42    {
 043        return await _store.CountAsync(filter.Apply, cancellationToken);
 044    }
 45
 46    private ValueTask OnSaveAsync(AlterationsElsaDbContext elsaDbContext, AlterationPlan entity, CancellationToken cance
 47    {
 048        elsaDbContext.Entry(entity).Property("SerializedAlterations").CurrentValue = _alterationSerializer.SerializeMany
 049        elsaDbContext.Entry(entity).Property("SerializedWorkflowInstanceFilter").CurrentValue = JsonSerializer.Serialize
 050        return default;
 51    }
 52
 53    [RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)"
 54    private ValueTask OnLoadAsync(AlterationsElsaDbContext elsaDbContext, AlterationPlan? entity, CancellationToken canc
 55    {
 056        if (entity is null)
 057            return default;
 58
 059        var alterationsJson = elsaDbContext.Entry(entity).Property<string>("SerializedAlterations").CurrentValue;
 060        var workflowInstanceFilterJson = elsaDbContext.Entry(entity).Property<string>("SerializedWorkflowInstanceFilter"
 061        entity.Alterations = _alterationSerializer.DeserializeMany(alterationsJson).ToList();
 062        entity.WorkflowInstanceFilter = JsonSerializer.Deserialize<AlterationWorkflowInstanceFilter>(workflowInstanceFil
 63
 064        return default;
 65    }
 66}