Class RateLimitAssertions
- Namespace
- TimeAssertions.TUnit
- Assembly
- TimeAssertions.TUnit.dll
Fluent rate-limit assertions on a chronologically-ordered sequence of invocation timestamps. The headline use case is a periodic-probe contract: "the failure handler must fire at most once per 30 seconds; subsequent failures inside that window are suppressed".
public static class RateLimitAssertions
- Inheritance
-
RateLimitAssertions
- Inherited Members
Remarks
The receiver is the recorded invocation log itself, not the action being invoked.
Consumer test code records timestamps via whatever instrumentation is natural (a
captured FakeLogCollector's log records, an explicit
List<T> populated in a wrapped callback, etc.) and asserts the log.
The assertion preserves input order verbatim. Caller is responsible for sorting if the underlying mechanism does not guarantee chronological order. Empty and single-element sequences pass trivially: no consecutive pair exists to violate.
Methods
WasInvokedAtMostOncePer(IReadOnlyList<DateTimeOffset>, TimeSpan)
Asserts that consecutive timestamps in the supplied sequence maintain at least the specified minimum interval. The first violating consecutive pair fails the assertion with a message naming the violating index, the observed gap, and the required minimum.
[GenerateAssertion(InlineMethodBody = false)]
public static AssertionResult WasInvokedAtMostOncePer(this IReadOnlyList<DateTimeOffset> timestamps, TimeSpan interval)
Parameters
timestampsIReadOnlyList<DateTimeOffset>The recorded invocation timestamps in chronological order. The first violating pair is reported by index; reporting stops at the first violation.
intervalTimeSpanThe minimum allowed gap between consecutive invocations. Must be non-negative.
Returns
- AssertionResult
TUnit.Assertions.Core.AssertionResult.Passed when every consecutive pair is at least
intervalapart, including the trivially-passing empty and single-element cases. Otherwise Failed(string) with a message naming the first violation.
Remarks
The boundary case gap == interval passes (the minimum is
inclusive). The violation predicate is gap < interval, so any
non-decreasing sequence with interval of
Zero trivially passes (including duplicate-timestamp
pairs whose gap is exactly zero). Strictly out-of-order pairs (negative gap)
fail at any non-negative interval.
Exceptions
- ArgumentNullException
timestampsis null.- ArgumentOutOfRangeException
intervalis negative.