< 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
30%
Covered lines: 6
Uncovered lines: 14
Coverable lines: 20
Total lines: 62
Line coverage: 30%
Branch coverage
16%
Covered branches: 3
Total branches: 18
Branch coverage: 16.6%
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()50%4475%
DispatchAsync()0%2040%
DispatchAsync()0%2040%
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>
 32913public class ValidatingWorkflowDispatcher(IWorkflowDispatcher decoratedService, IOptions<WorkflowDispatcherOptions> disp
 14{
 35215    private IWorkflowDispatcher DecoratedService { get; set; } = decoratedService;
 16
 17    /// <inheritdoc />
 18    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowDefinitionRequest request, DispatchWorkflo
 19    {
 2320        if (!ValidateChannel(options?.Channel))
 021            return DispatchWorkflowResponse.UnknownChannel();
 22
 2323        return await DecoratedService.DispatchAsync(request, options, cancellationToken);
 2324    }
 25
 26    /// <inheritdoc />
 27    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO
 28    {
 029        if (!ValidateChannel(options?.Channel))
 030            return DispatchWorkflowResponse.UnknownChannel();
 31
 032        return await DecoratedService.DispatchAsync(request, options, cancellationToken);
 033    }
 34
 35    /// <inheritdoc />
 36    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO
 37    {
 038        if (!ValidateChannel(options?.Channel))
 039            return DispatchWorkflowResponse.UnknownChannel();
 40
 041        return await DecoratedService.DispatchAsync(request, options, cancellationToken);
 042    }
 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    {
 2355        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}