< Summary

Information
Class: TeleFlow.Telegram.Internal.Options.TelegramClientOptionsValidator
Assembly: TeleFlow.Telegram.Client
File(s): /_/src/TeleFlow.Telegram.Client/Internal/Options/TelegramClientOptionsValidator.cs
Line coverage
82%
Covered lines: 19
Uncovered lines: 4
Coverable lines: 23
Total lines: 60
Line coverage: 82.6%
Branch coverage
77%
Covered branches: 14
Total branches: 18
Branch coverage: 77.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Validate(...)66.66%141275%
ValidateRetryAfter(...)100%66100%

File(s)

/_/src/TeleFlow.Telegram.Client/Internal/Options/TelegramClientOptionsValidator.cs

#LineLine coverage
 1namespace TeleFlow.Telegram.Internal.Options;
 2
 3internal static class TelegramClientOptionsValidator
 4{
 5    public static void Validate(TelegramClientOptions options)
 6    {
 4847        ArgumentNullException.ThrowIfNull(options);
 8
 4849        if (string.IsNullOrWhiteSpace(options.Token))
 10        {
 011            throw new InvalidOperationException("Telegram bot token must be configured.");
 12        }
 13
 48414        if (string.IsNullOrWhiteSpace(options.BaseUrl))
 15        {
 016            throw new InvalidOperationException("Telegram base URL must be configured.");
 17        }
 18
 48419        if (!Uri.TryCreate(options.BaseUrl, UriKind.Absolute, out _))
 20        {
 021            throw new InvalidOperationException("Telegram base URL must be an absolute URI.");
 22        }
 23
 48424        if (!Enum.IsDefined(options.Environment))
 25        {
 126            throw new InvalidOperationException(
 127                $"Telegram Bot API environment '{options.Environment}' is not supported.");
 28        }
 29
 48330        if (!TelegramBotUsernameNormalizer.TryNormalize(options.BotUsername, out _, out var botUsernameError))
 31        {
 532            throw new InvalidOperationException(botUsernameError);
 33        }
 34
 47835        if (options.Defaults is null)
 36        {
 037            throw new InvalidOperationException("Telegram bot defaults must be configured.");
 38        }
 39
 47840        ValidateRetryAfter(options.RetryAfter);
 47441    }
 42
 43    private static void ValidateRetryAfter(TelegramRetryAfterPolicy? policy)
 44    {
 47845        if (policy is null)
 46        {
 147            throw new InvalidOperationException("Telegram retry-after policy must be configured.");
 48        }
 49
 47750        if (policy.MaxRetries < 0)
 51        {
 152            throw new InvalidOperationException("Telegram retry-after maximum retry count must not be negative.");
 53        }
 54
 47655        if (policy.MaxDelay <= TimeSpan.Zero)
 56        {
 257            throw new InvalidOperationException("Telegram retry-after maximum retry delay must be greater than zero.");
 58        }
 47459    }
 60}