-
Notifications
You must be signed in to change notification settings - Fork 20
Use Cake's IFileSystem for read/write operations instead of System.IO.File #117
Description
Expected Behavior
When using a mock implementation of IFileSystem for testing a task that uses Cake.FileHelpers, the mocked file system is being used.
Current Behavior
Even though the ICakeContext passed to the File* aliases uses a mock implementation of IFileSystem, the current machine's real file system is used.
Possible Solution
Adapt the aliases provided by Cake.FileHelpers to avoid using System.IO.File and instead use the IFileSystem of the current ICakeContext.
Steps to Reproduce (for bugs)
The following example shows a test that should succeeds but instead fails with a DirectoryNotFoundException.
(The source code for FakeCakeContext can be found here)
public class FileHelpersTest
{
[Fact]
public void FileReadText_returns_expected_content()
{
// ARRANGE
var path = (FilePath)"X:\\SomeFile.txt";
var context = new FakeCakeContext();
context.FileSystem.CreateFile(path).SetContent("Hello World");
// ACT
var content = context.FileReadText(path);
// ASSERT
Assert.Equal("Hello World", content);
}
}Context
I am writing tests for Cake (Frosting) tasks that use "Cake.FileHelpers" and would like to use the FakeFileSystem class from the "Cake.Testing" package to mock the file system used by the tasks.
Your Environment
- Addin version used: 6.0.
- Cake Version used: 3.0.0
- Operating System: Windows 11