Skip to content

Instantly share code, notes, and snippets.

@tohagan
Last active June 8, 2016 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tohagan/5848eddc9bd57f313a8da509212007e3 to your computer and use it in GitHub Desktop.
Save tohagan/5848eddc9bd57f313a8da509212007e3 to your computer and use it in GitHub Desktop.
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(); } }
}
[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