< Summary

Information
Class: Elsa.Workflows.WorkflowBase<T>
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Abstractions/WorkflowBase.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 11
Coverable lines: 11
Total lines: 82
Line coverage: 0%
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%210%
get_Result()100%210%
BeforeBuildAsync(...)100%210%
AfterBuildAsync(...)0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Abstractions/WorkflowBase.cs

#LineLine coverage
 1using Elsa.Workflows.Memory;
 2using JetBrains.Annotations;
 3
 4namespace Elsa.Workflows;
 5
 6/// <summary>
 7/// A base class for implementing workflow definitions using the pipelineBuilder API.
 8/// </summary>
 9[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
 10public abstract class WorkflowBase : IWorkflow
 11{
 12    /// <summary>
 13    /// Invokes the specified <see cref="IWorkflowBuilder"/>.
 14    /// </summary>
 15    protected virtual ValueTask BuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default)
 16    {
 17        Build(builder);
 18        return ValueTask.CompletedTask;
 19    }
 20
 21    /// <summary>
 22    /// Invokes the specified <see cref="IWorkflowBuilder"/>.
 23    /// </summary>
 24    /// <param name="builder"></param>
 25    protected virtual void Build(IWorkflowBuilder builder)
 26    {
 27    }
 28
 29    /// <summary>
 30    /// Gives derived types a chance to setup the <see cref="IWorkflowBuilder"/> before the BuildAsync method is invoked
 31    /// </summary>
 32    protected virtual ValueTask BeforeBuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default
 33
 34    /// <summary>
 35    /// Gives derived types a chance to setup the <see cref="IWorkflowBuilder"/> after the BuildAsync method was invoked
 36    /// </summary>
 37    protected virtual ValueTask AfterBuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default)
 38
 39    async ValueTask IWorkflow.BuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken)
 40    {
 41        await BeforeBuildAsync(builder, cancellationToken);
 42        await BuildAsync(builder, cancellationToken);
 43        await AfterBuildAsync(builder, cancellationToken);
 44    }
 45}
 46
 47/// <summary>
 48/// A base class for implementing workflow definitions that can return a result using the pipelineBuilder API.
 49/// </summary>
 50public abstract class WorkflowBase<TResult> : WorkflowBase
 51{
 52    /// <inheritdoc />
 053    protected WorkflowBase()
 54    {
 055        Result = new("Result", default!);
 056    }
 57
 58    /// <summary>
 59    /// Use this variable from your workflow to assign a result value.
 60    /// </summary>
 061    protected Variable<TResult> Result { get; }
 62
 63    /// <inheritdoc />
 64    protected override ValueTask BeforeBuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = defaul
 65    {
 066        builder.Result = Result;
 067        return ValueTask.CompletedTask;
 68    }
 69
 70    /// <inheritdoc />
 71    protected override ValueTask AfterBuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default
 72    {
 073        var variables = builder.Variables;
 74
 075        if(!variables.Contains(Result))
 076           variables.Add(Result);
 77
 078        builder.Variables = variables;
 79
 080        return ValueTask.CompletedTask;
 81    }
 82}