Skip to content

Commit 63b5d5c

Browse files
LosManosfgreinacher
authored andcommitted
Let null MockFileData create empty file (#360)
Fixes #356
1 parent 06cd374 commit 63b5d5c

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public void MockFileSystem_GetFile_ShouldReturnFileRegisteredInConstructorWhenPa
5454
Assert.AreEqual(file1, result);
5555
}
5656

57+
[Test]
58+
public void MockFileSystem_AddFile_ShouldHandleNullFileDataAsEmpty()
59+
{
60+
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
61+
{
62+
{ @"c:\something\nullish.txt", null }
63+
});
64+
65+
var result = fileSystem.File.ReadAllText(@"c:\SomeThing\nullish.txt");
66+
67+
Assert.IsEmpty(result, "Null MockFileData should be allowed for and result in an empty file.");
68+
}
69+
5770
[Test]
5871
public void MockFileSystem_AddFile_ShouldRepaceExistingFile()
5972
{

System.IO.Abstractions.TestingHelpers/MockFileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void AddFile(string path, MockFileData mockFile)
138138
AddDirectory(directoryPath);
139139
}
140140

141-
SetEntry(fixedPath, mockFile);
141+
SetEntry(fixedPath, mockFile ?? new MockFileData(string.Empty));
142142
}
143143
}
144144

0 commit comments

Comments
 (0)