Avoiding flaky tests with TimeProvider and ITimer
This is an extract from Andrew Lock's blog. Jump over and check out his work, he is a very talented individual and has some awesome posts.
What's the problem with the existing APIs?
Even if you're new to C#, you have likely needed to get "the current time" at some point. The default way to do that is to use the DateTime.UtcNow
or DateTimeOffset.UtcNow
static properties. You can call these properties from anywhere in your code so they're an easy thing to reach for wherever you are.