< Summary

Information
Class: Elsa.Extensions.ActivityExecutionContextRecordExtensions
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/ActivityExecutionContextRecordExtensions.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 39
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CaptureActivityExecutionRecordAsync()100%11100%
GetOrMapCapturedActivityExecutionRecordAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/ActivityExecutionContextRecordExtensions.cs

#LineLine coverage
 1using Elsa.Workflows;
 2using Elsa.Workflows.Runtime;
 3using Elsa.Workflows.Runtime.Entities;
 4
 5// ReSharper disable once CheckNamespace
 6namespace Elsa.Extensions;
 7
 8public static class ActivityExecutionContextRecordExtensions
 9{
 10    private const string ActivityExecutionRecordKey = "CapturedActivityExecutionRecord";
 11
 12    /// <summary>
 13    /// Captures the activity execution record for the provided <see cref="ActivityExecutionContext"/> and stores it in 
 14    /// </summary>
 15    public static async Task CaptureActivityExecutionRecordAsync(this ActivityExecutionContext context)
 16    {
 133417        var mapper = context.GetRequiredService<IActivityExecutionMapper>();
 133418        var record = await mapper.MapAsync(context);
 133419        context.TransientProperties[ActivityExecutionRecordKey] = record;
 133420    }
 21
 22    /// <summary>
 23    /// Retrieves the captured activity execution record from the transient properties of the provided <see cref="Activi
 24    /// If the record is not found, it maps and returns a new activity execution record using the <see cref="IActivityEx
 25    /// </summary>
 26    public static async Task<ActivityExecutionRecord> GetOrMapCapturedActivityExecutionRecordAsync(this ActivityExecutio
 27    {
 28        // If the record is already captured in the transient properties, return it, as it will contain the serialized s
 29        // This is useful for scenarios where the activity execution state may change after the record is captured, such
 379130        if (context.TransientProperties.TryGetValue(ActivityExecutionRecordKey, out var capturedRecord))
 129331            return (ActivityExecutionRecord)capturedRecord;
 32
 33        // If the record is not captured, map a new activity execution record using the mapper.
 249834        var mapper = context.GetRequiredService<IActivityExecutionMapper>();
 249835        var record = await mapper.MapAsync(context);
 36
 249837        return record;
 379138    }
 39}