< Summary

Information
Class: TeleFlow.Framework.RateLimiting.UpdateRateLimitDecision
Assembly: TeleFlow.Framework.Core
File(s): /_/src/TeleFlow.Framework.Core/RateLimiting/UpdateRateLimitDecision.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 66
Line coverage: 100%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)66.66%66100%
get_Accepted()100%11100%
get_IsAccepted()100%11100%
get_IsRejected()100%11100%
Rejected(...)100%11100%

File(s)

/_/src/TeleFlow.Framework.Core/RateLimiting/UpdateRateLimitDecision.cs

#LineLine coverage
 1namespace TeleFlow.Framework.RateLimiting;
 2
 3/// <summary>
 4/// Describes whether an incoming update can continue through the framework pipeline after
 5/// update-level rate limiting has been evaluated.
 6/// </summary>
 7public readonly record struct UpdateRateLimitDecision
 8{
 9    private const byte AcceptedKind = 0;
 10    private const byte RejectedKind = 1;
 11
 12    private readonly byte _kind;
 13
 14    private UpdateRateLimitDecision(
 15        byte kind,
 16        TimeSpan? retryAfter,
 17        string? policyName)
 18    {
 219        if (retryAfter < TimeSpan.Zero)
 20        {
 121            throw new ArgumentOutOfRangeException(
 122                nameof(retryAfter),
 123                retryAfter,
 124                "Rate-limit retry delay must not be negative.");
 25        }
 26
 127        _kind = kind;
 28        RetryAfter = retryAfter;
 129        PolicyName = string.IsNullOrWhiteSpace(policyName) ? null : policyName;
 130    }
 31
 32    /// <summary>
 33    /// Gets a decision that allows the update to continue through the framework pipeline.
 34    /// </summary>
 335    public static UpdateRateLimitDecision Accepted => default;
 36
 37    /// <summary>
 38    /// Gets whether the update is allowed to continue through the framework pipeline.
 39    /// </summary>
 540    public bool IsAccepted => _kind == AcceptedKind;
 41
 42    /// <summary>
 43    /// Gets whether the update was rejected by a rate limiter.
 44    /// </summary>
 145    public bool IsRejected => _kind == RejectedKind;
 46
 47    /// <summary>
 48    /// Gets the optional delay after which the update sender may retry, when the limiter can provide it.
 49    /// </summary>
 50    public TimeSpan? RetryAfter { get; }
 51
 52    /// <summary>
 53    /// Gets the optional developer-controlled policy name that rejected the update.
 54    /// </summary>
 55    public string? PolicyName { get; }
 56
 57    /// <summary>
 58    /// Creates a decision that rejects the update and stops the framework pipeline.
 59    /// </summary>
 60    public static UpdateRateLimitDecision Rejected(
 61        TimeSpan? retryAfter = null,
 62        string? policyName = null)
 63    {
 264        return new UpdateRateLimitDecision(RejectedKind, retryAfter, policyName);
 65    }
 66}