System.IO.Abstractions
System.IO.Abstractions copied to clipboard
feat: #872 Set Creation, LastAccess and LastWrite time for files
Implements #872
Adjust CreationTime, LastAccessTime and LastWriteTime when interacting with files in the MockFileSystem.
Provides a means to mock the used DateTime by calling e.g.
var fixedTime = new DateTime(2022, 01, 01);
var fileSystem = new MockFileSystem().MockTime(() => fixedTime);
// All times will now be set to the fixedTime.
Implementes the following logic in MockFile: All these cases are covered by unit tests in MockFileAdjustTimesTest
- When creating files CreationTime, LastAccessTime and LastWriteTime are set to the current time
- When changing files (
WriteAllText,WriteAllBytes,AppendAllText,OpenWrite,Open) LastAccessTime and LastWriteTime are set to the current time CreationTime is left unchanged - When reading files (
ReadAllText,ReadAllLines,ReadAllBytes,OpenRead) LastAccessTime is set to the current time CreationTime and LastWriteTime are left unchanged - When setting attributes or ACLs (
SetAttributes,SetAccessControl) LastAccessTime is set to the current time CreationTime and LastWriteTime are left unchanged - When moving files (
Move) LastAccessTime is set to the current time CreationTime and LastWriteTime are left unchanged - When copying files (
Copy) CreationTime and LastAccessTime of the copied file in the destination directory is set to the current time LastWriteTime and all times of the source file are left unchanged
Please note, that I changed the Interface IMockFileDataAccessor.
This interface looks like it is intended for internal use, but as it is public this could be considered a breaking change...
I am not sure what I should do: I could increase the version or use default interface methods from C# 8
If this is an accepted approach, I could also try to have a look at #839, which deals with the times of directories. This would probably be quite similar...
Sorry @vbreuss, I'm a bit busy with other things, will try to have a look by the end of this week!
@siprbaum : I merged the latest changes, so that this branch is up to date. All comments are either fixed and resolved, or I left a comment explaining, why I implemented it this way. Could you please have a look again at this pull request?
@siprbaum : Thanks for the review! I implemented the changes and answered your findings. Can you please have a look again, and resolve the comments, that you agree with?
Regarding the user detectable behaviour change:
As we are now setting the times correctly, the behaviour changes when previously in the tests you would (incorrectly) rely upon unchanged times for the files.
However I am still unsure, if I should increment the version when considering my previous comment in this pull request, regarding the change in the interface IMockFileDataAccessor.
What do you think?
@fgreinacher : I merged the latest main branch and answered or fixed all review comments.
Can you please have a look?
This is addressed in release v17.2.3.
This is addressed in release v17.2.3.