< Summary

Information
Class: TeleFlow.Telegram.Webhooks.Internal.TelegramRawWebhookOptionsValidator
Assembly: TeleFlow.Telegram.Webhooks
File(s): /_/src/TeleFlow.Telegram.Webhooks/Internal/TelegramRawWebhookOptionsValidator.cs
Line coverage
93%
Covered lines: 15
Uncovered lines: 1
Coverable lines: 16
Total lines: 35
Line coverage: 93.7%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Validate(...)75%4491.66%
ValidateStatusCode(...)100%66100%

File(s)

/_/src/TeleFlow.Telegram.Webhooks/Internal/TelegramRawWebhookOptionsValidator.cs

#LineLine coverage
 1namespace TeleFlow.Telegram.Webhooks.Internal;
 2
 3internal static class TelegramRawWebhookOptionsValidator
 4{
 5    public static void Validate(TelegramRawWebhookOptions options)
 6    {
 247        ArgumentNullException.ThrowIfNull(options);
 8
 249        if (options.SecretToken is not null)
 10        {
 711            if (string.IsNullOrWhiteSpace(options.SecretToken))
 12            {
 013                throw new InvalidOperationException("Telegram webhook secret token must not be empty.");
 14            }
 15
 716            options.SecretToken = options.SecretToken.Trim();
 17        }
 18
 2419        ValidateStatusCode(
 2420            options.InvalidPayloadStatusCode,
 2421            nameof(TelegramRawWebhookOptions.InvalidPayloadStatusCode));
 2322        ValidateStatusCode(
 2323            options.SecretTokenFailureStatusCode,
 2324            nameof(TelegramRawWebhookOptions.SecretTokenFailureStatusCode));
 2225    }
 26
 27    private static void ValidateStatusCode(int statusCode, string optionName)
 28    {
 4729        if (statusCode is < 100 or > 599)
 30        {
 231            throw new InvalidOperationException(
 232                $"{optionName} must be a valid HTTP status code between 100 and 599.");
 33        }
 4534    }
 35}