Closed mboukhlouf closed 4 years ago
You need it for Unit tests. Sample: When you create an object you want to fill CreatedAt by the DateTime.UtcNow The current DateTime is a kind of dependency on the environment. How to write tests to CreatedAt? The easiest way - create an IDateTime interface and mock it in tests. And one more benefit - dependency on the IDateTime is explicit. You can see that this class depends on environment.
You need it for Unit tests. Sample: When you create an object you want to fill CreatedAt by the DateTime.UtcNow The current DateTime is a kind of dependency on the environment. How to write tests to CreatedAt? The easiest way - create an IDateTime interface and mock it in tests. And one more benefit - dependency on the IDateTime is explicit. You can see that this class depends on environment.
Thank you so much.
What's the point of having the IDateTime interface? The implementation MachineDateTime just calls DateTime.Now for the Now property.