< Summary

Information
Class: TeleFlow.Telegram.Internal.Options.TelegramStateKeyOptions
Assembly: TeleFlow.Framework
File(s): /_/src/TeleFlow.Framework/Internal/Options/TelegramStateKeyOptions.cs
Line coverage
92%
Covered lines: 12
Uncovered lines: 1
Coverable lines: 13
Total lines: 36
Line coverage: 92.3%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FromToken(...)100%22100%
TryResolveBotId(...)75%4490%

File(s)

/_/src/TeleFlow.Framework/Internal/Options/TelegramStateKeyOptions.cs

#LineLine coverage
 1using System.Globalization;
 2
 3namespace TeleFlow.Telegram.Internal.Options;
 4
 5/// <summary>
 6/// Stores Telegram-specific state-key settings resolved during Telegram framework registration,
 7/// before updates reach state middleware and handler dispatch.
 8/// </summary>
 9internal sealed record class TelegramStateKeyOptions(long? BotId)
 10{
 11    public static TelegramStateKeyOptions FromToken(string token)
 12    {
 48013        return TryResolveBotId(token, out var botId)
 48014            ? new TelegramStateKeyOptions(botId)
 48015            : new TelegramStateKeyOptions(BotId: null);
 16    }
 17
 18    private static bool TryResolveBotId(string token, out long botId)
 19    {
 48020        botId = default;
 21
 48022        if (string.IsNullOrWhiteSpace(token))
 23        {
 024            return false;
 25        }
 26
 48027        var separatorIndex = token.IndexOf(':', StringComparison.Ordinal);
 28
 48029        return separatorIndex > 0 &&
 48030            long.TryParse(
 48031                token.AsSpan(0, separatorIndex),
 48032                NumberStyles.None,
 48033                CultureInfo.InvariantCulture,
 48034                out botId);
 35    }
 36}