Skip to content

Set Creation, LastAccess and LastWrite time for files #872

Closed

Description

@vbreuss

Is your feature request related to a problem? Please describe.
I want to test a functionality that relies on the "GetLastWriteTimeUtc" method to detect when a file was last changed.
This property in MockFileSystem only returns a fixed value "2010-02-03 20:00:00"

Describe the solution you'd like
MockFileSystem should set the creation, last access and last write times and return the correct values.
Ideally you would also provide an optional callback or property to set, so that I can even mock the time that is stored.

Describe alternatives you've considered
None, as the times are not even tracked anywhere internally.

Additional context
I would like e.g. the following unit test to pass:

  [Theory]
  [WithAutoData]
  public void GetCreationTimeUtc_ShouldBeSet(string file)
  {
    var now = DateTime.UtcNow;
    var sut = new MockFileSystem();
    sut.File.WriteAllText("foo.txt", "xyz");

    var result = sut.File.GetCreationTimeUtc("foo.txt");

    result.Kind.Should().Be(DateTimeKind.Utc);
    result.Should().BeOnOrAfter(now);
  }

Activity

  1. added
    state: needs discussion
    type: enhancement
    on Aug 9, 2022
  2. fgreinacher commented on Aug 10, 2022

    @fgreinacher
    Contributor

    We already have the partially, see #861.

    Makes sense to implement this consistently for all operations 👍

  3. added
    area: testinghelpers
    flag: good-first-issue
    state: ready to pick
    and removed
    state: needs discussion
    flag: good-first-issue
    on Aug 10, 2022
  4. vbreuss commented on Aug 10, 2022

    @vbreuss
    MemberAuthor

    I would give it a try...

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: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions