< Summary

Information
Class: Elsa.Workflows.Runtime.ValidatingWorkflowDispatcher
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/ValidatingWorkflowDispatcher.cs
Line coverage
60%
Covered lines: 12
Uncovered lines: 8
Coverable lines: 20
Total lines: 62
Line coverage: 60%
Branch coverage
50%
Covered branches: 9
Total branches: 18
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_DecoratedService()100%11100%
DispatchAsync()75%4475%
DispatchAsync()75%4475%
DispatchAsync()50%4475%
DispatchAsync()0%2040%
ValidateChannel(...)50%22100%
GetChannelExists(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/ValidatingWorkflowDispatcher.cs

#LineLine coverage
 1using Elsa.Workflows.Runtime.Options;
 2using Elsa.Workflows.Runtime.Requests;
 3using Elsa.Workflows.Runtime.Responses;
 4using Microsoft.Extensions.Options;
 5
 6namespace Elsa.Workflows.Runtime;
 7
 8/// <summary>
 9/// Validates the workflow request before dispatching it to the workflow dispatcher.
 10/// </summary>
 11/// <param name="decoratedService">The workflow dispatcher to decorate.</param>
 12/// <param name="dispatcherOptions">The workflow dispatcher options.</param>
 50813public class ValidatingWorkflowDispatcher(IWorkflowDispatcher decoratedService, IOptions<WorkflowDispatcherOptions> disp
 14{
 55515    private IWorkflowDispatcher DecoratedService { get; set; } = decoratedService;
 16
 17    /// <inheritdoc />
 18    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowDefinitionRequest request, DispatchWorkflo
 19    {
 3720        if (!ValidateChannel(options?.Channel))
 021            return DispatchWorkflowResponse.UnknownChannel();
 22
 3723        return await DecoratedService.DispatchAsync(request, options, cancellationToken);
 3724    }
 25
 26    /// <inheritdoc />
 27    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO
 28    {
 229        if (!ValidateChannel(options?.Channel))
 030            return DispatchWorkflowResponse.UnknownChannel();
 31
 232        return await DecoratedService.DispatchAsync(request, options, cancellationToken);
 233    }
 34
 35    /// <inheritdoc />
 36    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO
 37    {
 838        if (!ValidateChannel(options?.Channel))
 039            return DispatchWorkflowResponse.UnknownChannel();
 40
 841        return await DecoratedService.DispatchAsync(request, options, cancellationToken);
 842    }
 43
 44    /// <inheritdoc />
 45    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchResumeWorkflowsRequest request, DispatchWorkflowOp
 46    {
 047        if (!ValidateChannel(options?.Channel))
 048            return DispatchWorkflowResponse.UnknownChannel();
 49
 050        return await DecoratedService.DispatchAsync(request, options, cancellationToken);
 051    }
 52
 53    private bool ValidateChannel(string? channelName)
 54    {
 4755        return string.IsNullOrEmpty(channelName) || GetChannelExists(channelName);
 56    }
 57
 58    private bool GetChannelExists(string channelName)
 59    {
 060        return dispatcherOptions.Value.Channels.Any(x => x.Name == channelName);
 61    }
 62}