< Summary

Information
Class: Elsa.Resilience.ResilienceStrategyConfigEvaluator
Assembly: Elsa.Resilience.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Resilience.Core/Services/ResilienceStrategyConfigEvaluator.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 51
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
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%
EvaluateAsync()0%4260%
ResolveByIdentifierAsync()0%620%
ResolveByExpressionAsync()0%7280%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Resilience.Core/Services/ResilienceStrategyConfigEvaluator.cs

#LineLine coverage
 1using System.Dynamic;
 2using Elsa.Expressions.Contracts;
 3using Elsa.Expressions.Helpers;
 4using Elsa.Expressions.Models;
 5using Elsa.Resilience.Models;
 6using Elsa.Resilience.Serialization;
 7
 8namespace Elsa.Resilience;
 9
 010public class ResilienceStrategyConfigEvaluator(IResilienceStrategyCatalog catalog, IExpressionEvaluator expressionEvalua
 11{
 12    public async Task<IResilienceStrategy?> EvaluateAsync(ResilienceStrategyConfig? config, ExpressionExecutionContext c
 13    {
 014        if (config == null) return null;
 15
 016        var mode = config.Mode;
 17
 018        return mode switch
 019        {
 020            ResilienceStrategyConfigMode.Identifier => await ResolveByIdentifierAsync(config, cancellationToken),
 021            ResilienceStrategyConfigMode.Expression => await ResolveByExpressionAsync(config, context, cancellationToken
 022            _ => null
 023        };
 024    }
 25
 26    private async Task<IResilienceStrategy?> ResolveByIdentifierAsync(ResilienceStrategyConfig config, CancellationToken
 27    {
 028        var strategyId = config.StrategyId;
 029        return string.IsNullOrWhiteSpace(strategyId)
 030            ? null
 031            : await catalog.GetAsync(strategyId, cancellationToken);
 032    }
 33
 34    private async Task<IResilienceStrategy?> ResolveByExpressionAsync(ResilienceStrategyConfig config, ExpressionExecuti
 35    {
 036        var expression = config.Expression;
 37
 038        if (expression == null)
 039            return null;
 40
 041        var result = await expressionEvaluator.EvaluateAsync<object>(expression, context, ExpressionEvaluatorOptions.Emp
 42
 043        return result switch
 044        {
 045            string strategyId => await catalog.GetAsync(strategyId, cancellationToken),
 046            IResilienceStrategy strategy => strategy,
 047            ExpandoObject expando => expando.ConvertTo<IResilienceStrategy>(new(strategySerializer.SerializerOptions)),
 048            _ => null
 049        };
 050    }
 51}