Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -793,13 +793,32 @@ public void MockFileInfo_Replace_ShouldThrowIfDestinationFileDoesNotExist()
Assert.Throws<FileNotFoundException>(() => fileInfo.Replace(path2, null));
}

[Test]
public void MockFileInfo_Exists_LazyLoadsData()
{
// Arrange
var fileSystem = new MockFileSystem();
var path1 = XFS.Path(@"c:\temp\file1.txt");
var fileInfo = fileSystem.FileInfo.FromFileName(path1);
var cachedFileInfo = fileSystem.FileInfo.FromFileName(path1);
_ = cachedFileInfo.Exists; // this forces a lazyload of the data.

// Act
fileSystem.AddFile(path1, new MockFileData("1"));

// Assert
Assert.IsTrue(fileInfo.Exists);
Assert.IsFalse(cachedFileInfo.Exists, "Cached MockFileInfo should still return the cached value");
}

[Test]
public void MockFileInfo_Exists_ShouldUpdateCachedDataOnRefresh()
{
// Arrange
var fileSystem = new MockFileSystem();
var path1 = XFS.Path(@"c:\temp\file1.txt");
var fileInfo = fileSystem.FileInfo.FromFileName(path1);
fileInfo.Refresh();

// Act
fileSystem.AddFile(path1, new MockFileData("1"));
Expand All @@ -812,9 +831,11 @@ public void MockFileInfo_Exists_ShouldUpdateCachedDataOnRefresh()
[Test]
public void MockFileInfo_Create_ShouldUpdateCachedDataAndReturnTrueForExists()
{
// Arrange
IFileSystem fileSystem = new MockFileSystem();
var path = XFS.Path(@"c:\temp\file1.txt");
IFileInfo fileInfo = fileSystem.FileInfo.FromFileName(path);
fileInfo.Refresh();

// Act
fileInfo.Create().Dispose();
Expand All @@ -827,9 +848,11 @@ public void MockFileInfo_Create_ShouldUpdateCachedDataAndReturnTrueForExists()
[Test]
public void MockFileInfo_CreateText_ShouldUpdateCachedDataAndReturnTrueForExists()
{
// Arrange
IFileSystem fileSystem = new MockFileSystem();
var path = XFS.Path(@"c:\temp\file1.txt");
IFileInfo fileInfo = fileSystem.FileInfo.FromFileName(path);
fileInfo.Refresh();

// Act
fileInfo.CreateText().Dispose();
Expand All @@ -841,9 +864,11 @@ public void MockFileInfo_CreateText_ShouldUpdateCachedDataAndReturnTrueForExists
[Test]
public void MockFileInfo_Delete_ShouldUpdateCachedDataAndReturnFalseForExists()
{
// Arrange
var fileSystem = new MockFileSystem();
var path = XFS.Path(@"c:\temp\file1.txt");
IFileInfo fileInfo = fileSystem.FileInfo.FromFileName(path);
fileInfo.Refresh();

// Act
fileInfo.Delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void MockFileSystem_AddFile_ShouldMatchCapitalization_PartialMatch_Furthe
}

[Test]
public void MockFileSystem_AddFile_ShouldMarkFileAsExisting()
public void MockFileSystem_FileInfoExists_ShouldBeTrueIfAFileWasAddedBeforeMockFileDataWasLazyLoaded()
{
// Arrange
var fileSystem = new MockFileSystem();
Expand Down