Skip to content

Incorrect LastAccessTime & LastWriteTime for directory #839

Open

Description

@CzBuCHi

Describe the bug
Mock file system is not storing LastAccessTime & LastWriteTime properties for directories

To Reproduce

var fileSystem = new MockFileSystem();
var info = fileSystem.DirectoryInfo.FromDirectoryName(@"C:\\Parent\\Dir");
info.Create();
info.LastWriteTime = new DateTime(2001, 2, 3);

var c= fileSystem.DirectoryInfo.FromDirectoryName("C:\\Parent");
foreach (var info in parent.EnumerateDirectories()) {
   var thisShouldBeTrue = info.LastAccessTime  == new DateTime(2001, 2, 3);
}

Expected behavior
variable thisShouldBeTrue should be true.

Additional context
class MockFileSystem should have method AddDirectory(string path, MockDirectoryInfo mock) so i can set directory attributes same way as in method AddFile. MockDirectoryInfo is derived from MockFileInfo but with no content (only default ctor) and with attribute FileAttributes.Directory.

Activity

  1. added
    state: needs discussion
    type: bug
    on Apr 29, 2022
  2. fgreinacher commented on May 6, 2022

    @fgreinacher
    Contributor

    Sounds useful, maybe @siprbaum you also have an opinion here 😀

  3. added
    state: ready to pick
    area: testinghelpers
    and removed
    state: needs discussion
    on May 6, 2022
  4. siprbaum commented on May 6, 2022

    @siprbaum
    Contributor

    First, let me adress thispart:

    Additional context class MockFileSystem should have method AddDirectory(string path, MockDirectoryInfo mock) so i can set directory attributes same way as in method AddFile. MockDirectoryInfo is derived from MockFileInfo but with no content (only default ctor) and with attribute FileAttributes.Directory.

    I think you meant MockDirectoryInfo -> MockDirectoryData and MockFileInfo -> MockFileData.
    Adding a method

    AddDirectory(string path, MockDirectoryData mock)
                              ^^^^ ...Data not ...Info
    

    could be useful, I believe.

    Concerning the automatic LastAccessTime update when enumerating the directroy:

    var fileSystem = new MockFileSystem();
    var info = fileSystem.DirectoryInfo.FromDirectoryName(@"C:\\Parent\\Dir");
    info.Create();
    info.LastWriteTime = new DateTime(2001, 2, 3);
    
    var c= fileSystem.DirectoryInfo.FromDirectoryName("C:\\Parent");
    foreach (var info in parent.EnumerateDirectories()) {
       var thisShouldBeTrue = info.LastAccessTime  == new DateTime(2001, 2, 3);
    }
    

    Expected behavior variable thisShouldBeTrue should be true.

    Isn't this also depending on the underlying OS, e.g Linux vs Windows if and when the xxxTimes are updated?
    But I have to admit I haven't looked to deeply into it.

    So at least this second part sounds more controversial than the first part to me.

  5. CaringDev commented on Nov 24, 2026

    @CaringDev
    Contributor

    @vbreuss I take it this could be closed given your fix?

  6. vbreuss commented on Nov 24, 2026

    @vbreuss
    Member

    @CaringDev : I don't think so. #875 was for files, this issue is for directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersstate: ready to picktype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions