< Summary

Information
Class: TeleFlow.Telegram.TelegramAllowedUpdates
Assembly: TeleFlow.Framework.LongPolling
File(s): /_/src/TeleFlow.Framework.LongPolling/TelegramAllowedUpdates.cs
Line coverage
94%
Covered lines: 18
Uncovered lines: 1
Coverable lines: 19
Total lines: 62
Line coverage: 94.7%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.cctor()100%11100%
Only(...)100%11100%
Only(...)87.5%8893.33%

File(s)

/_/src/TeleFlow.Framework.LongPolling/TelegramAllowedUpdates.cs

#LineLine coverage
 1namespace TeleFlow.Telegram;
 2
 3public sealed class TelegramAllowedUpdates
 4{
 5    private TelegramAllowedUpdates(TelegramAllowedUpdatesMode mode, IReadOnlyList<TelegramUpdateType> updateTypes)
 6    {
 7        Mode = mode;
 8        UpdateTypes = updateTypes;
 39    }
 10
 11    internal TelegramAllowedUpdatesMode Mode { get; }
 12
 13    internal IReadOnlyList<TelegramUpdateType> UpdateTypes { get; }
 14
 115    public static TelegramAllowedUpdates Auto { get; } = new(TelegramAllowedUpdatesMode.Auto, []);
 16
 117    public static TelegramAllowedUpdates All { get; } = new(TelegramAllowedUpdatesMode.All, []);
 18
 19    public static TelegramAllowedUpdates Only(params TelegramUpdateType[] updateTypes)
 20    {
 321        return Only((IEnumerable<TelegramUpdateType>)updateTypes);
 22    }
 23
 24    public static TelegramAllowedUpdates Only(IEnumerable<TelegramUpdateType> updateTypes)
 25    {
 326        ArgumentNullException.ThrowIfNull(updateTypes);
 27
 328        var normalized = updateTypes.ToArray();
 329        if (normalized.Length == 0)
 30        {
 131            throw new ArgumentException("At least one Telegram update type must be specified.", nameof(updateTypes));
 32        }
 33
 1234        foreach (var updateType in normalized)
 35        {
 436            if (string.IsNullOrWhiteSpace(updateType.Value))
 37            {
 038                throw new ArgumentException("Telegram update type values must not be empty.", nameof(updateTypes));
 39            }
 40        }
 41
 242        var duplicate = normalized
 443            .GroupBy(static updateType => updateType.Value, StringComparer.Ordinal)
 544            .FirstOrDefault(static group => group.Count() > 1);
 45
 246        if (duplicate is not null)
 47        {
 148            throw new ArgumentException(
 149                $"Duplicate Telegram update type '{duplicate.Key}' was specified.",
 150                nameof(updateTypes));
 51        }
 52
 153        return new TelegramAllowedUpdates(TelegramAllowedUpdatesMode.Only, normalized);
 54    }
 55}
 56
 57internal enum TelegramAllowedUpdatesMode
 58{
 59    Auto,
 60    All,
 61    Only
 62}