Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

What's the point of having the IDateTime interface? #270

Closed
mboukhlouf opened this issue Aug 31, 2020 · 2 comments
Closed

What's the point of having the IDateTime interface? #270

mboukhlouf opened this issue Aug 31, 2020 · 2 comments

Comments

@mboukhlouf
Copy link

What's the point of having the IDateTime interface? The implementation MachineDateTime just calls DateTime.Now for the Now property.

@AndreiTsvettsikh
Copy link

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.

@mboukhlouf
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants