.Nettuce

Code Salad

  Home  |   Contact  |   Syndication    |   Login
  36 Posts | 0 Stories | 36 Comments | 0 Trackbacks

News

Twitter












Archives

    public static class DateTimeProvider
    {
        static Func<DateTime> nowFunc = () => DateTime.UtcNow;

        public static DateTime Now
        {
            get { return nowFunc(); }
            set { nowFunc = () => value; }
        }
    }
By default it returns DateTime.UtcNow; override in your tests by calling
DateTimeProvider.Now = DateTime.Today;


posted on Wednesday, October 10, 2012 8:26 PM

Feedback

# re: A DateTime provider to help unit test DateTime 10/10/2012 9:28 PM Marc Brooks
Almost perfect... just change the property name to UtcNow so it doesn't show up in my code-smeller...

Post A Comment
Title:
Name:
Email:
Comment:
Verification: