Skip to content

Commit

Permalink
fix: Refresh FileInfo & DirectoryInfo after adding to MockFileSystem (#…
Browse files Browse the repository at this point in the history
…984)

Modify the `IFileInfo` and `IDirectoryInfo` overloads of `AddFile()`, `AddEmptyFile()`, or `AddDirectory()` in `MockFileSystem`, to call `Refresh()` on those objects after the paths they refer to are created.
  • Loading branch information
rcdailey committed May 12, 2023
1 parent ccdc24d commit 49747fa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public void AddEmptyFile(string path)
public void AddEmptyFile(IFileInfo path)
{
AddEmptyFile(path.FullName);
path.Refresh();
}

/// <summary>
Expand All @@ -234,6 +235,7 @@ public void AddEmptyFile(IFileInfo path)
public void AddDirectory(IDirectoryInfo path)
{
AddDirectory(path.FullName);
path.Refresh();
}

/// <summary>
Expand All @@ -244,6 +246,7 @@ public void AddDirectory(IDirectoryInfo path)
public void AddFile(IFileInfo path, MockFileData data)
{
AddFile(path.FullName, data);
path.Refresh();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,39 @@ public void MockFileSystem_AddEmptyFile_ShouldBeEmpty()
Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo(""));
}

[Test]
public void MockFileSystem_AddEmptyFile_ShouldExist()
{
var fileSystem = new MockFileSystem();
var path = fileSystem.FileInfo.New(XFS.Path(@"c:\some\file.txt"));

fileSystem.AddEmptyFile(path);

Assert.That(path.Exists, Is.True);
}

[Test]
public void MockFileSystem_AddFile_ShouldExist()
{
var fileSystem = new MockFileSystem();
var path = fileSystem.FileInfo.New(XFS.Path(@"c:\some\file.txt"));

fileSystem.AddFile(path, new MockFileData("stuff"));

Assert.That(path.Exists, Is.True);
}

[Test]
public void MockFileSystem_AddDirectory_ShouldExist()
{
var fileSystem = new MockFileSystem();
var path = fileSystem.DirectoryInfo.New(XFS.Path(@"c:\thedir"));

fileSystem.AddDirectory(path);

Assert.That(path.Exists, Is.True);
}

[Test]
public void MockFileSystem_ByDefault_IsSerializable()
{
Expand Down

0 comments on commit 49747fa

Please sign in to comment.