Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

FakeTimeProvider Class

Definition

Namespace:
Microsoft.Extensions.Time.Testing
Assembly:
Microsoft.Extensions.TimeProvider.Testing.dll
Package:
Microsoft.Extensions.TimeProvider.Testing v10.7.0
Source:
FakeTimeProvider.cs
Source:
FakeTimeProvider.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents a synthetic time provider that can be used to enable deterministic behavior in tests.

public ref class FakeTimeProvider : TimeProvider
public class FakeTimeProvider : TimeProvider
type FakeTimeProvider = class
 inherit TimeProvider
Public Class FakeTimeProvider
Inherits TimeProvider
Inheritance
FakeTimeProvider

Constructors

Name Description
FakeTimeProvider()

Initializes a new instance of the FakeTimeProvider class.

FakeTimeProvider(DateTimeOffset)

Initializes a new instance of the FakeTimeProvider class.

Properties

Name Description
AutoAdvanceAmount

Gets or sets the amount of time by which time advances whenever the clock is read.

LocalTimeZone

Gets a TimeZoneInfo object that represents the local time zone according to this TimeProvider's notion of time.

Start

Gets the starting date and time for this provider.

TimestampFrequency

Gets the amount by which the value from GetTimestamp() increments per second.

Methods

Name Description
AdjustTime(DateTimeOffset)

Sets the date and time in the UTC time zone.

Advance(TimeSpan)

Advances time by a specific amount.

CreateTimer(TimerCallback, Object, TimeSpan, TimeSpan)

Creates a new ITimer instance, using TimeSpan values to measure time intervals.

GetElapsedTime(Int64, Int64)

Gets the elapsed time between two timestamps retrieved using GetTimestamp().

(Inherited from TimeProvider)
GetElapsedTime(Int64)

Gets the elapsed time since the startingTimestamp value retrieved using GetTimestamp().

(Inherited from TimeProvider)
GetLocalNow()

Gets a DateTimeOffset value that is set to the current date and time according to this TimeProvider's notion of time based on GetUtcNow(), with the offset set to the LocalTimeZone's offset from Coordinated Universal Time (UTC).

(Inherited from TimeProvider)
GetTimestamp()

Gets the current high-frequency value designed to measure small time intervals with high accuracy in the timer mechanism.

GetUtcNow()

Gets a DateTimeOffset value whose date and time are set to the current Coordinated Universal Time (UTC) date and time and whose offset is Zero, all according to this TimeProvider's notion of time.

SetLocalTimeZone(TimeZoneInfo)

Sets the local time zone.

SetUtcNow(DateTimeOffset)

Advances the date and time in the UTC time zone.

ToString()

Returns a string representation this provider's idea of current time.

Extension Methods

Name Description
CreateCancellationTokenSource(TimeProvider, TimeSpan)

Initializes a new instance of the CancellationTokenSource class that will be canceled after the specified TimeSpan.

Delay(TimeProvider, TimeSpan, CancellationToken)

Creates a task that completes after a specified time interval.

Applies to


Feedback

Was this page helpful?