TDD FileLoader v1.4
Using mocking in the test
The Unit Test
[Test]
public void load_all_of_file_using_delegate_with_mock()
{
// arrange
string fileToLoad = "c:/tmp/KeyboardHandler.java.txt";
FileLoader cut = new FileLoader();
List<string> pretendFileContent = new();
pretendFileContent.Add("Hello");
pretendFileContent.Add("world");
int expectedBytesRead = 10;
var file = Substitute.For<MyFile>();
file.ReadLines(fileToLoad).Returns(pretendFileContent);
// act
int bytesRead = cut.LoadFile(fileToLoad, (fname) =>
{
IEnumerable<string> result = file.ReadLines(fileToLoad);
return result;
});
// assert
Assert.AreEqual(expectedBytesRead, bytesRead);
}