Class PrimeTestClock
- Namespace
- KZDev.SystemClock.PrimeTime.Testing
- Assembly
- KZDev.SystemClock.PrimeTime.Testing.dll
System Clock partial of PrimeTestClock: BCL DateTimeOffset virtual storage and PrimeTestClockEvent payloads for ClockEvents.
public sealed class PrimeTestClock : PrimeTestTimeBase, IPrimeTestClock, IPrimeTestTime, IPrimeClock, IPrimeTime
- Inheritance
-
PrimeTestClock
- Implements
- Inherited Members
Remarks
Shared march, runner, and persist-on-read behavior live in the common partial; see IPrimeTestClock.
Constructors
- PrimeTestClock()
Initializes a new instance with virtual UTC time set to UtcNow.
- PrimeTestClock(DateTimeOffset)
Initializes a new instance with the specified initial virtual UTC time.
Properties
- LocalNowDateOnly
Gets the current local date as DateOnly.
- LocalNowDateTime
Gets the current local date and time as a DateTime.
- LocalNowDateTimeOffset
Gets the current local date and time as a DateTimeOffset.
- LocalNowTimeOnly
Gets the current local time-of-day as TimeOnly.
- LocalScheduleTimeZone
Gets the time zone used to resolve the local calendar date and local wall-clock time for local day-time timer registration (BCL time-of-day surface when available).
- UtcNowDateOnly
Gets the current UTC date as DateOnly.
- UtcNowDateTime
Gets the current UTC date and time as a DateTime.
- UtcNowDateTimeOffset
Gets the current UTC date and time as a DateTimeOffset.
- UtcNowTimeOnly
Gets the current UTC time-of-day as TimeOnly.
Methods
- Advance(TimeSpan)
Advances virtual time forward by marching to each earliest due instant up to the new horizon, then dispatching delays, time expiries, and timers at each step.
- OnSchedulingMutatedWhileGateHeld()
Notifies the automatic runner that scheduling changed while KZDev.SystemClock.PrimeTime.Testing.PrimeTestTimeBase.Gate is held.
- RegisterAsyncTimeOfDay(LocalTimeOfDay, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a local time-of-day timer with an asynchronous callback that receives timer context and cancellation token. Other
RegisterAsyncTimeOfDayoverloads for LocalTimeOfDay are provided as extension methods.
- RegisterAsyncTimeOfDay(UtcTimeOfDay, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a UTC time-of-day timer with an asynchronous callback that receives timer context and cancellation token. Other
RegisterAsyncTimeOfDayoverloads for UtcTimeOfDay are provided as extension methods.
- RegisterAsyncTimer(TimeSpan, TimeSpan, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, IntervalTimerOptions?)
Registers an interval timer with an initial delay, a repeat interval, and an asynchronous callback that receives timer context and cancellation token. Other
RegisterAsyncTimeroverloads are provided as extension methods.
- RegisterTimeOfDay(LocalTimeOfDay, Action<ClockTimerCallbackContext>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a local time-of-day timer with a synchronous callback that receives timer context and optional state. Other
RegisterTimeOfDayoverloads for LocalTimeOfDay are provided as extension methods.
- RegisterTimeOfDay(UtcTimeOfDay, Action<ClockTimerCallbackContext>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a UTC time-of-day timer with a synchronous callback that receives timer context and optional state. Other
RegisterTimeOfDayoverloads for UtcTimeOfDay are provided as extension methods.
- RegisterTimer(TimeSpan, TimeSpan, Action<ClockTimerCallbackContext>, CancellationToken, object?, IntervalTimerOptions?)
Registers an interval timer with an initial delay, a repeat interval, and a synchronous callback that receives timer context. Other
RegisterTimeroverloads are provided as extension methods.
- RunFor(TimeSpan)
Starts a bounded automatic run that advances virtual time by
durationat a 1:1 real-time pace (one second of virtual time per real second), then stops when that virtual elapsed time is reached.
- RunFor(TimeSpan, TimeSpan)
Starts a bounded automatic run that advances virtual time by
durationatperSecondRate(virtual time per one real second), then stops when that virtual elapsed time is reached.
- SetTime(DateTimeOffset)
Sets the current UTC time of the clock to the specified value. When the clock is not running, this is the time returned by UtcNowDateTimeOffset and related members.
- Start(TimeSpan?)
Starts a background runner that advances virtual time toward the next delay, time-expiry, timer due instant, or virtual-minute ClockEvents heartbeat, scaled by the run rate.
- Stop()
Stops the automatic runner and clears the monotonic run anchor.
Events
- ClockEvents
Occurs when the clock publishes a discriminated lifecycle or virtual-time event.