< Summary

Information
Class: TeleFlow.Telegram.Internal.TelegramRawLongPollingOptionsValidator
Assembly: TeleFlow.Telegram.LongPolling
File(s): /_/src/TeleFlow.Telegram.LongPolling/Internal/TelegramRawLongPollingOptionsValidator.cs
Line coverage
90%
Covered lines: 18
Uncovered lines: 2
Coverable lines: 20
Total lines: 48
Line coverage: 90%
Branch coverage
75%
Covered branches: 12
Total branches: 16
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Validate(...)50%9875%
ValidateAllowedUpdates(...)100%88100%

File(s)

/_/src/TeleFlow.Telegram.LongPolling/Internal/TelegramRawLongPollingOptionsValidator.cs

#LineLine coverage
 1namespace TeleFlow.Telegram.Internal;
 2
 3internal static class TelegramRawLongPollingOptionsValidator
 4{
 5    public static void Validate(TelegramRawLongPollingOptions options)
 6    {
 247        ArgumentNullException.ThrowIfNull(options);
 8
 249        if (options.TimeoutSeconds <= 0)
 10        {
 011            throw new InvalidOperationException("Raw long polling timeout must be greater than zero.");
 12        }
 13
 2414        if (options.Limit is < 1 or > 100)
 15        {
 016            throw new InvalidOperationException("Raw long polling limit must be between 1 and 100.");
 17        }
 18
 2419        ValidateAllowedUpdates(options.AllowedUpdates);
 2220        TelegramRawLongPollingBackoff.ValidateOptions(options.Backoff);
 2221    }
 22
 23    private static void ValidateAllowedUpdates(IReadOnlyList<string>? allowedUpdates)
 24    {
 2425        if (allowedUpdates is null)
 26        {
 1527            return;
 28        }
 29
 9530        foreach (var updateType in allowedUpdates)
 31        {
 3932            if (string.IsNullOrWhiteSpace(updateType))
 33            {
 134                throw new InvalidOperationException("Raw long polling allowed update values must not be empty.");
 35            }
 36        }
 37
 838        var duplicate = allowedUpdates
 3739            .GroupBy(static updateType => updateType, StringComparer.Ordinal)
 4440            .FirstOrDefault(static group => group.Count() > 1);
 41
 842        if (duplicate is not null)
 43        {
 144            throw new InvalidOperationException(
 145                $"Duplicate raw long polling allowed update value '{duplicate.Key}' was specified.");
 46        }
 747    }
 48}