Skip to content
Snippets Groups Projects
  1. Sep 10, 2022
  2. Sep 04, 2022
  3. Aug 30, 2022
  4. Aug 26, 2022
  5. Aug 19, 2022
  6. Aug 15, 2022
  7. Aug 10, 2022
  8. Aug 03, 2022
  9. Aug 02, 2022
  10. Jul 19, 2022
    • Robert Dailey's avatar
      fix: improve cache invalidation in MockDirectoryInfo (#862) · 96f9886a
      Robert Dailey authored
      
      When invoking the `Create()` and `Delete()` methods on
      `MockDirectoryInfo`, the `Exists` property should intrinsically invoke
      `Refresh()` the next time it is called. This is necessary to prevent
      returning stale state about the directory after those operations.
      
      Additional test cases have been added for `MoveTo()` as well, to ensure
      it also not returning stale state.
      
      For context, this change was motivated by PR #828 where similar issues
      were solved in `MockFileInfo`.
      
      Co-authored-by: default avatarFlorian Greinacher <florian@greinacher.de>
      v17.0.24
      96f9886a
  11. Jul 15, 2022
  12. Jul 12, 2022
  13. Jul 04, 2022
  14. Jun 27, 2022
  15. Jun 10, 2022
  16. Jun 09, 2022
  17. May 29, 2022
  18. May 22, 2022
  19. May 20, 2022
  20. May 18, 2022
  21. May 17, 2022
  22. May 16, 2022
  23. May 15, 2022
  24. May 11, 2022
  25. Apr 26, 2022
  26. Apr 25, 2022
    • Peter Baumann's avatar
      fix: correct MockFileInfo and MockDirectoryInfo for non existing files/directories (#834) · c66bf871
      Peter Baumann authored
      Fixes #829 
      Fixes #830
      
      BREAKING CHANGE: `MockFileData.NullObject` is now `internal`. Users need to create new `MockFileData` instances for representing arbitrary data.
      
      Detailed changes:
      
      * make MockFileData.NullObject internal
      
      The `MockFileData.NullObject` was introduced in commit
      0d85da38 as a way to represent the data
      of a non-existing file. Nevertheless, the issue #830 shows that at least
      one person used it as "some arbitrary MockFileData of an existing file
      I don't care about".
      
      Reason: As we are going to really make this the data representing a
      non-existing file by fixing/changing the `Attribute` property in one of
      the next commits, make this property internal and thereby breaking to
      force all consumers to really think about their tests and if they
      really ment a non-existing file or simply some arbirary data.
      Otherwise, the upcoming change would have nasty side effects if the
      NullObject is used for arbitrary data of an existing file.
      
      An alternative considered would be to rename this static property (which
      is also breaking) to any users, but decided against it as I couldn't
      think of a usecase where explicitly creating a file or directory which
      doesn't exist instead of relying on what the library will for you when
      being asked for a non-existing file.
      
      E.g. it is the difference of
      
        var fs = new MockFileSystem();
        var nonExistingPath = XFS.Path(@"c:\some\non\existing\file.txt");
        fs.AddFile(nonExistingPath, MockFileData.NullObject);
        var fi = fs.FileInfo.FromFilename(nonExistingPath);
      
      vs simply relying on the library to return the correct data for the
      non-existing file:
      
        var fs = new MockFileSystem();
        var nonExistingPath = XFS.Path(@"c:\some\non\existing\file.txt");
        var fi = fs.FileInfo.FromFilename(nonExistingPath);
      
      All tests are adapted to no longer use the MockFileData.NullObject.
      
      * fix: return -1 in MockFileInfo.Attributes and MockDirectoryInfo
      
      According to the Microsoft documentation[1] the `Attributes` property of
      FileSystemInfo (base of FileInfo and DirectoryInfo) returns
      (FileAttributes)(-1) for a file/directory which doesn't exist when the
      object instance is created. The on disk content is not looked at when
      calling the `Attributes` property, only a pre-cached value is returned.
      Only calling `Refresh` will read from disk.
      
      To be on the safe side, I checked the documented behaviour with the real
      implemenation with the below code snipped and it indeed shows the
      documented behaviour.
      
          var fs = new FileSystem();
          var expected = (FileAttributes)(-1);
          var fi = fs.FileInfo.FromFileName(@"x:\not-existing\path");
          Assert.That(fi.Attributes, Is.EqualTo(expected));
      
      This lead to quite some needed code adaptions, especially in the area of
      the `GetMockFileDataForRead` methods, as those now no longer throw an
      exception. Furthermore, as cachedMockFileData is always a non-null instance,
      get rid of the logic checking for null in `GetMockFileDataForRead` and
      `MockFileInfo.CopyTo(string destFileName)` method.
      
      Also ensure that the used MockFileData is always `Clone`ed  (and therefore
      even the MockFileData.NullObject) so that we operate on our own copy
      and don't get any updates done in the FileSystem.
      
      With this new semantics the `MockDiretory.Exists` method requires special
      treatment, as we now must check for a valid MockFileData by checking
      if Attributes != -1.
      
      [1]: https://docs.microsoft.com/en-us/dotnet/api/system.io.filesysteminfo.attributes?view=net-6.0#remarks
      
      * MockFileInfo: add test setting Attributes on non-existing file
      
      Ensure that when setting the Attributes property on a non existing file
      the appropriate FileNotFoundException is thrown, as documented in [1].
      
      [1]: https://docs.microsoft.com/en-us/dotnet/api/system.io.filesysteminfo.attributes?view=net-6.0#remarks
      
      * MockDirectory: add tests for Time property getters on non existing file
      
      Add tests that when trying to retrieve the time properties of a non
      existing file returns 12:00 midnight, January 1, 1601 A.D. (C.E.)
      Coordinated Universal Time (UTC) as documented in [1]
      
      [1]: https://docs.microsoft.com/en-us/dotnet/api/system.io.filesysteminfo.lastaccesstime?view=net-6.0#remarks
      
      * MockFileInfo: add tests for Time property getters on non existing file
      
      Add tests that when trying to retrieve the time properties of a non
      existing file returns 12:00 midnight, January 1, 1601 A.D. (C.E.)
      Coordinated Universal Time (UTC) as documented in [1]
      
      [1]: https://docs.microsoft.com/en-us/dotnet/api/system.io.filesysteminfo.lastaccesstime?view=net-6.0#remarks
      
      * Fix MockDirectoryInfo: throw correct exception on non-existing directory
      
      When setting one of the Time properties or the `Attributes` property
      on a non-existing directory, a DirectoryNotFoundException should be thrown.
      Fix the code by throwing the correct exception (it did throw a
      FileNotFoundExecption before) and add the missing tests.
      
      * Increase major version to 17.0
      
      MockFileData.NullObject was made internal, which is a breaking change,
      therefore increase the major version.
      v17.0.1
      c66bf871
  27. Apr 24, 2022
  28. Mar 23, 2022
  29. Mar 22, 2022
  30. Mar 14, 2022
  31. Mar 11, 2022
Loading