WALTER | Workable Algorithms for Location-aware Transmission, Encryption Response

TestClock Class

Class TestClock allows you to manipulate the flow of time in your tests. It implements the IClock interface and can be used to replace the system clock in tests, enabling you to mock or set the time as required.

Namespace:  Walter
Assembly:  Walter (in Walter.dll)

Syntax


public sealed class TestClock : LicenseBase, 
	IClock

Examples


This example demonstrates using IClock in a class and in unit tests for time-sensitive operations:
Using IClock in a class and unit test
// Class using the IClock
class Record
{
    public Record(string name)
    {
        Time = IClock.Instance.Now; // Set the current time
        Name = name;
    }

    /// <summary>
    /// Time the action was recorded
    /// </summary>
    public DateTime Time { get; }

    // Other properties...
}

// In your unit test or replay class, validate logic based on date and time
var clock = new Walter.TestClock(TimeSeries[0].Time); // Initialize TestClock with a specific time
Walter.IClock.Instance = clock; // Swap the IClock instance with TestClock

foreach (var item in TimeSeries)
{
    var laps = item.Time - IClock.Instance.Now; // Calculate time difference
    clock.Add(laps); // Move the clock forward
    var record = new Record(item.Activity);
    // Perform time-sensitive activity using the time set by IClock
    bool isAllowed = UserCanLogin(record);
}

Inheritance Hierarchy


Object
  Walter.Model..::..LicenseBase
    Walter..::..TestClock