If file not very big, mock nothing, create file in test folder, and use it for test.
You, obviously, want extract file name as parameter to your function, so you can load any file in the tests.
public void ProcessDataFromFile(string path)
{
var data = string.Join("", System.IO.File.ReadAllLines(path));
var text= new StringBuilder(data);
// process data
}
In case file is big and makes tests slow - create an abstraction wrapper for reading data, which you can mock in the tests.
public interface IFileReader
{
string[] ReadAllLinesFrom(string path);
}
In the production code "inject" abstraction to the method where you need read a file
public void ProcessDataFromFile(string path, IFileReader reader)
{
var data = string.Join("", reader.ReadAllLinesFrom(path));
var text= new StringBuilder(data);
// process data
}
For the tests you can create own implementation of IFileReader
public class FakeFileReader : IFileReader
{
public Dictionary<string, string[]> Files { get; }
public FakeFileReader ()
{
Files = new Dictionary<string, string[]>();
}
public string[] ReadAllLinesFrom(string path)
{
return Files.GetValueOrDefault(path);
}
}
And tests
public void Test()
{
var fakeReader = new FakeFileReader();
var path = "pathToSomeFile"
var data = new[] { "Line 1", "Line 2", Line 3" };
fakeReader.Files.Add(path, data)
ProcessDataFromFile(path, fakeReader);
// Assert
}