Well, you can easily create your own injectable interface:
public interface IClock
{
DateTime UtcNow { get; }
}
public class SystemClock : IClock
{
public DateTime UtcNow { get { return DateTime.UtcNow; } }
}
public class FakeClock : IClock
{
public DateTime UtcNow { get; set; }
}
Inject that into your code as you would any other dependency. (I view both "give me the current time" and "give me a random number" as dependencies which should generally be injected just like anything else.)
All that being said, when Noda Time is production-ready, we will provide injectable clocks so you won't need to write your own :)
While you can mock this, I personally wouldn't... mocking is usually best for testing protocols where you care when dependencies are called and how often, etc. In this case you've got a "dumb" dependency, so effectively stubbing it is more appropriate... and that's more easily done with a concrete fake class. All IMO, of course.
Note that I've deliberately emphasized the UTC side of things... you can always call ToLocalTime()
if you need to, but usually working in UTC is a better idea. In Noda Time the clock returns an Instant
instead, but then we have a rather richer set of types to play with :)