Created
March 20, 2018 10:55
-
-
Save tomaustin700/339d18b9802e9f757ae74ce30c5a49b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Used for getting DateTime.Now(), time is changeable for unit testing | |
/// </summary> | |
public static class SystemTime | |
{ | |
/// <summary> Normally this is a pass-through to DateTime.Now, but it can be overridden with SetDateTime( .. ) for testing or debugging. | |
/// </summary> | |
public static Func<DateTime> Now = () => DateTime.Now; | |
/// <summary> Set time to return when SystemTime.Now() is called. | |
/// </summary> | |
public static void SetDateTime(DateTime dateTimeNow) | |
{ | |
Now = () => dateTimeNow; | |
} | |
/// <summary> Resets SystemTime.Now() to return DateTime.Now. | |
/// </summary> | |
public static void ResetDateTime() | |
{ | |
Now = () => DateTime.Now; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment