< Summary

Information
Class: Elsa.Persistence.EFCore.Modules.Runtime.EFCoreTriggerStore
Assembly: Elsa.Persistence.EFCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Runtime/TriggerStore.cs
Line coverage
65%
Covered lines: 19
Uncovered lines: 10
Coverable lines: 29
Total lines: 90
Line coverage: 65.5%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
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%11100%
FindManyAsync()100%11100%
FindManyAsync(...)100%210%
FindManyAsync()100%210%
ReplaceAsync()100%22100%
DeleteManyAsync()100%11100%
OnSaveAsync(...)50%22100%
OnLoadAsync(...)50%4480%

File(s)

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

#LineLine coverage
 1using Elsa.Common.Entities;
 2using Elsa.Common.Models;
 3using Elsa.Extensions;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Runtime;
 6using Elsa.Workflows.Runtime.Entities;
 7using Elsa.Workflows.Runtime.Filters;
 8using Elsa.Workflows.Runtime.OrderDefinitions;
 9using JetBrains.Annotations;
 10using Open.Linq.AsyncExtensions;
 11
 12namespace Elsa.Persistence.EFCore.Modules.Runtime;
 13
 14/// <inheritdoc />
 15[UsedImplicitly]
 32116public class EFCoreTriggerStore(EntityStore<RuntimeElsaDbContext, StoredTrigger> store, IPayloadSerializer serializer) :
 17{
 18    /// <inheritdoc />
 19    public async ValueTask SaveAsync(StoredTrigger record, CancellationToken cancellationToken = default)
 20    {
 021        await store.SaveAsync(record, OnSaveAsync, cancellationToken);
 022    }
 23
 24    /// <inheritdoc />
 25    public async ValueTask SaveManyAsync(IEnumerable<StoredTrigger> records, CancellationToken cancellationToken = defau
 26    {
 027        await store.SaveManyAsync(records, OnSaveAsync, cancellationToken);
 028    }
 29
 30    /// <inheritdoc />
 31    public async ValueTask<StoredTrigger?> FindAsync(TriggerFilter filter, CancellationToken cancellationToken = default
 32    {
 233        return await store.FindAsync(filter.Apply, OnLoadAsync, filter.TenantAgnostic, cancellationToken);
 234    }
 35
 36    /// <inheritdoc />
 37    public async ValueTask<IEnumerable<StoredTrigger>> FindManyAsync(TriggerFilter filter, CancellationToken cancellatio
 38    {
 52439        return await store.QueryAsync(filter.Apply, OnLoadAsync, filter.TenantAgnostic, cancellationToken);
 52440    }
 41
 42    public ValueTask<Page<StoredTrigger>> FindManyAsync(TriggerFilter filter, PageArgs pageArgs, CancellationToken cance
 43    {
 044        return FindManyAsync(filter, pageArgs, new StoredTriggerOrder<string>(x => x.Id, OrderDirection.Ascending), canc
 45    }
 46
 47    public async ValueTask<Page<StoredTrigger>> FindManyAsync<TProp>(TriggerFilter filter, PageArgs pageArgs, StoredTrig
 48    {
 049        var count = await store.QueryAsync(filter.Apply, OnLoadAsync, cancellationToken).LongCount();
 050        var results = await store.QueryAsync(queryable => filter.Apply(queryable).OrderBy(order).Paginate(pageArgs).Orde
 051        return new(results, count);
 052    }
 53
 54    /// <inheritdoc />
 55    public async ValueTask ReplaceAsync(IEnumerable<StoredTrigger> removed, IEnumerable<StoredTrigger> added, Cancellati
 56    {
 48857        var removedList = removed.ToList();
 58
 48859        if(removedList.Count > 0)
 60        {
 861            var filter = new TriggerFilter { Ids = removedList.Select(r => r.Id).ToList() };
 462            await DeleteManyAsync(filter, cancellationToken);
 63        }
 64
 48865        await store.SaveManyAsync(added, OnSaveAsync, cancellationToken);
 48866    }
 67
 68    /// <inheritdoc />
 69    public async ValueTask<long> DeleteManyAsync(TriggerFilter filter, CancellationToken cancellationToken = default)
 70    {
 471        return await store.DeleteWhereAsync(filter.Apply, cancellationToken);
 472    }
 73
 74    private ValueTask OnSaveAsync(RuntimeElsaDbContext dbContext, StoredTrigger entity, CancellationToken cancellationTo
 75    {
 1376        dbContext.Entry(entity).Property("SerializedPayload").CurrentValue = entity.Payload != null ? serializer.Seriali
 1377        return default;
 78    }
 79
 80    private ValueTask OnLoadAsync(RuntimeElsaDbContext dbContext, StoredTrigger? entity, CancellationToken cancellationT
 81    {
 9882        if (entity is null)
 083            return ValueTask.CompletedTask;
 84
 9885        var json = dbContext.Entry(entity).Property<string>("SerializedPayload").CurrentValue;
 9886        entity.Payload = !string.IsNullOrEmpty(json) ? serializer.Deserialize(json) : null;
 87
 9888        return ValueTask.CompletedTask;
 89    }
 90}