Geeks With Blogs
.Nettuce Code Salad
    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 | Back to top


Comments on this post: A DateTime provider to help unit test DateTime

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

Your comment:
 (will show your gravatar)


Copyright © Jon Canning | Powered by: GeeksWithBlogs.net | Join free