< Summary

Information
Class: TeleFlow.Telegram.Internal.Handlers.TelegramCommandPolicy
Assembly: TeleFlow.Framework
File(s): /_/src/TeleFlow.Framework/Internal/Handlers/TelegramCommandPolicy.cs
Line coverage
92%
Covered lines: 12
Uncovered lines: 1
Coverable lines: 13
Total lines: 45
Line coverage: 92.3%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)66.66%6691.66%

File(s)

/_/src/TeleFlow.Framework/Internal/Handlers/TelegramCommandPolicy.cs

#LineLine coverage
 1using TeleFlow.Annotations;
 2
 3namespace TeleFlow.Telegram.Internal.Handlers;
 4
 5internal sealed class TelegramCommandPolicy
 6{
 17    public static TelegramCommandPolicy Default { get; } = new(["/"], allowSpaceAfterPrefix: false, ignoreCase: true);
 8
 9    public TelegramCommandPolicy(
 10        IReadOnlyList<string> prefixes,
 11        bool allowSpaceAfterPrefix,
 12        bool ignoreCase,
 13        CommandPrefixMode prefixMode = CommandPrefixMode.Required)
 14    {
 93415        ArgumentNullException.ThrowIfNull(prefixes);
 16
 93417        if (!Enum.IsDefined(prefixMode))
 18        {
 019            throw new InvalidOperationException($"Telegram command prefix mode '{prefixMode}' is not supported.");
 20        }
 21
 93422        if (prefixes.Count == 0 || prefixes.Any(string.IsNullOrWhiteSpace))
 23        {
 124            throw new InvalidOperationException("Telegram command route prefixes must contain at least one non-empty pre
 25        }
 26
 93327        Prefixes = prefixes
 96128            .Select(static prefix => prefix.Trim())
 93329            .Distinct(StringComparer.Ordinal)
 5630            .OrderByDescending(static prefix => prefix.Length)
 5631            .ThenBy(static prefix => prefix, StringComparer.Ordinal)
 93332            .ToArray();
 33        AllowSpaceAfterPrefix = allowSpaceAfterPrefix;
 34        IgnoreCase = ignoreCase;
 35        PrefixMode = prefixMode;
 93336    }
 37
 38    public IReadOnlyList<string> Prefixes { get; }
 39
 40    public bool AllowSpaceAfterPrefix { get; }
 41
 42    public bool IgnoreCase { get; }
 43
 44    public CommandPrefixMode PrefixMode { get; }
 45}