3 ms·
We use a "service" class with an internal timer that returns ".now()" and that implements an interface. The .ctor initialize the service's date with Datetime.n
by whynotmaybe 3y ago
We use a "service" class with an internal timer that returns ".now()" and that implements an interface.
The .ctor initialize the service's date with Datetime.now().
We use dependency injection wherever the service is required.
With this, we can manage 2 things
1. The service can go faster or slower than the real time by changing the timer's interval so we can simulate time depend behaviour in the app while testing.
2. We can mock the service when testing with a simple counter that's increased each time “.now()" is called.