Class ProtoClock
The clock a suite controls: a TimeProvider whose UTC time only moves when the test moves it. The run owns one instance (seeding each test's clock), and every test gets its own, so advancing time in one test never leaks into another. Only GetUtcNow() is virtual: timers created from this provider still run on real time.
public sealed class ProtoClock : TimeProvider
- Inheritance
-
ProtoClock
- Inherited Members
- Extension Methods
Constructors
ProtoClock()
Creates a clock at the current real time, for a run that does not care where it starts.
public ProtoClock()
ProtoClock(DateTimeOffset)
Creates a clock at a fixed instant, so every test starts from the same moment.
public ProtoClock(DateTimeOffset startUtc)
Parameters
startUtcDateTimeOffset
Properties
LocalTimeZone
Gets the local time zone according to this TimeProvider's notion of time.
public override TimeZoneInfo LocalTimeZone { get; }
Property Value
Methods
Advance(TimeSpan)
Moves the clock forward, which is what a time-dependent test does instead of sleeping.
public void Advance(TimeSpan delta)
Parameters
deltaTimeSpan
GetUtcNow()
Gets the current Coordinated Universal Time (UTC) date and time with an offset of zero, according to this TimeProvider's notion of time.
public override DateTimeOffset GetUtcNow()
Returns
SetUtcNow(DateTimeOffset)
Sets the clock to an exact instant, for tests that jump rather than elapse.
public void SetUtcNow(DateTimeOffset utcNow)
Parameters
utcNowDateTimeOffset