< Summary

Information
Class: Elsa.Workflows.WorkflowBase
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Abstractions/WorkflowBase.cs
Line coverage
88%
Covered lines: 8
Uncovered lines: 1
Coverable lines: 9
Total lines: 82
Line coverage: 88.8%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
BuildAsync(...)100%11100%
Build(...)100%210%
BeforeBuildAsync(...)100%11100%
AfterBuildAsync(...)100%11100%
Elsa-Workflows-IWorkflow-BuildAsync()100%11100%

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    {
 102817        Build(builder);
 102818        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    {
 027    }
 28
 29    /// <summary>
 30    /// Gives derived types a chance to setup the <see cref="IWorkflowBuilder"/> before the BuildAsync method is invoked
 31    /// </summary>
 102832    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>
 102837    protected virtual ValueTask AfterBuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default)
 38
 39    async ValueTask IWorkflow.BuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken)
 40    {
 102841        await BeforeBuildAsync(builder, cancellationToken);
 102842        await BuildAsync(builder, cancellationToken);
 102843        await AfterBuildAsync(builder, cancellationToken);
 102844    }
 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 />
 53    protected WorkflowBase()
 54    {
 55        Result = new("Result", default!);
 56    }
 57
 58    /// <summary>
 59    /// Use this variable from your workflow to assign a result value.
 60    /// </summary>
 61    protected Variable<TResult> Result { get; }
 62
 63    /// <inheritdoc />
 64    protected override ValueTask BeforeBuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = defaul
 65    {
 66        builder.Result = Result;
 67        return ValueTask.CompletedTask;
 68    }
 69
 70    /// <inheritdoc />
 71    protected override ValueTask AfterBuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default
 72    {
 73        var variables = builder.Variables;
 74
 75        if(!variables.Contains(Result))
 76           variables.Add(Result);
 77
 78        builder.Variables = variables;
 79
 80        return ValueTask.CompletedTask;
 81    }
 82}