Class FakeClock
Clock which can be constructed with an initial instant, and then advanced programmatically.
This class is designed to be used when testing classes which take an IClock as a dependency.
Since 1.0.x
Availability net35-Client
Inheritance
Object
FakeClock
Implements
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Namespace: NodaTime.Testing
Assembly: NodaTime.Testing.dll
Syntax
public sealed class FakeClock : IClock
Remarks
This class is somewhere between a fake and a stub, depending on how it's used - if it's set to
AutoAdvance then time will pass, but in a pretty odd way (i.e. dependent on how
often it's consulted).
Constructors
FakeClock(Instant)
Creates a fake clock initially set to the given instant, with no auto-advance.
Since 1.0.x
Availability net35-Client
Declaration
public FakeClock(Instant initial)
Parameters
| Type | Name | Description |
|---|---|---|
| Instant | initial |
FakeClock(Instant, Duration)
Creates a fake clock initially set to the given instant, with a given level of auto-advance.
Since 1.0.x
Availability net35-Client
Declaration
public FakeClock(Instant initial, Duration autoAdvance)
Parameters
| Type | Name | Description |
|---|---|---|
| Instant | initial | |
| Duration | autoAdvance |
Properties
AutoAdvance
Amount of time to advance the clock by each time Now is fetched.
Since 1.0.x
Availability net35-Client
Declaration
public Duration AutoAdvance { get; set; }
Property Value
| Type | Description |
|---|---|
| Duration |
Remarks
This defaults to zero, in which case the clock doesn't change other than by calls
to Reset(Instant). The value may be negative, to simulate particularly odd
system clock effects.
Now
Returns the "current time" for this clock. Unlike a normal clock, this
property will return the same value from repeated calls until one of the methods
to change the time is called.
Since 1.0.x
Availability net35-Client
Declaration
public Instant Now { get; }
Property Value
| Type | Description |
|---|---|
| Instant |
Methods
Advance(Duration)
Advances the clock by the given duration.
Since 1.0.x
Availability net35-Client
Declaration
public void Advance(Duration duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Duration | duration |
AdvanceDays(Int64)
Advances the clock by the given number of standard (24-hour) days.
Since 1.0.x
Availability net35-Client
Declaration
public void AdvanceDays(long days)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | days |
AdvanceHours(Int64)
Advances the clock by the given number of hours.
Since 1.0.x
Availability net35-Client
Declaration
public void AdvanceHours(long hours)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | hours |
AdvanceMilliseconds(Int64)
Advances the clock by the given number of milliseconds.
Since 1.0.x
Availability net35-Client
Declaration
public void AdvanceMilliseconds(long milliseconds)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | milliseconds |
AdvanceMinutes(Int64)
Advances the clock by the given number of minutes.
Since 1.0.x
Availability net35-Client
Declaration
public void AdvanceMinutes(long minutes)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | minutes |
AdvanceSeconds(Int64)
Advances the clock by the given number of seconds.
Since 1.0.x
Availability net35-Client
Declaration
public void AdvanceSeconds(long seconds)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | seconds |
AdvanceTicks(Int64)
Advances the clock by the given number of ticks.
Since 1.0.x
Availability net35-Client
Declaration
public void AdvanceTicks(long ticks)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | ticks |
FromUtc(Int32, Int32, Int32)
Returns a fake clock initially set to midnight of the given year/month/day in UTC in the ISO calendar.
Since 1.0.x
Availability net35-Client
Declaration
public static FakeClock FromUtc(int year, int month, int dayOfMonth)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | year | |
| Int32 | month | |
| Int32 | dayOfMonth |
Returns
| Type | Description |
|---|---|
| FakeClock |
FromUtc(Int32, Int32, Int32, Int32, Int32, Int32)
Returns a fake clock initially set to the given year/month/day/time in UTC in the ISO calendar.
Since 1.0.x
Availability net35-Client
Declaration
public static FakeClock FromUtc(int year, int month, int dayOfMonth, int hour, int minute, int second)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | year | |
| Int32 | month | |
| Int32 | dayOfMonth | |
| Int32 | hour | |
| Int32 | minute | |
| Int32 | second |
Returns
| Type | Description |
|---|---|
| FakeClock |
Reset(Instant)
Resets the clock to the given instant.
Since 1.0.x
Availability net35-Client
Declaration
public void Reset(Instant instant)
Parameters
| Type | Name | Description |
|---|---|---|
| Instant | instant |