Last active
June 8, 2016 07:30
-
-
Save tohagan/5848eddc9bd57f313a8da509212007e3 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
public static class SystemTime | |
{ | |
public static Func<DateTime> DateProvider = () => DateTime.Now; | |
public static void Reset() { DateProvider = () => DateTime.Now; } | |
public static DateTime Now { get { return DateProvider(); } } | |
} |
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
[TestFixture] | |
class MyDateTimeTests | |
{ | |
private DateTime now = new DateTime(2016, 6, 5, 9, 0, 0); | |
[TestFixtureSetUp] | |
public void TestFixtureSetUp() | |
{ | |
// Set SystemTime.Now = 9am Sunday 5/6/2016 to test business days | |
SystemTime.DateProvider = () => now; | |
} | |
[TestFixtureTearDown] | |
public void TestFixtureTearDown() | |
{ | |
SystemTime.Reset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment