So I’m writing a cache system (not too complicated, but it has very nice semantics) with a ttl (time to live) for items.
Of course the ttl must be unit tested, but since one can’t inject a new implementaton of “IDateTime” or “ITimeSpan” in C# (because there is no such thing), how would you go about that?
Write a new component “IDateTimeProvider” and “DateTimeProvider” first, which one can mockup then?
Isn’t reimplementing parts of the .NET runtime library… overkill?
Edit: Thank you all for your amazing answers! I know now exactly what I’m going to do!
You might want to see this question:
How do I MOQ the System.IO.FileInfo class… or any other class without an interface?
In a nutshell you’ll either need to make a wrapper class yourself, or use a library that already provides wrapper classes for DateTime, like SystemWrapper.