I was also looking for how to mock a FileStream via System.IO.Abstractions and couldn't see it initially. It's Hanging off the FileInfo Object. It results in slightly clunky code and required a cast. My Original Code:
FileStream fileStreamBack = null;
using (fileStreamBack = new FileStream(fileFrom, FileMode.Open, FileAccess.Read))
using (var fileStreamf = new FileStream(fileTo, FileMode.Create, FileAccess.Write))
{
fileStreamBack.CopyTo(fileStreamf); // Use the .Net
fileStreamBack.Flush(); // Making sure
fileStreamBack.Close(); // Making sure
}
Now Replaced with
FileStream fileStreamBack = null;
using (fileStreamBack = (FileStream)_fileSystem.FileInfo.FromFileName(fileFrom).Open(FileMode.Open, FileAccess.Read))
using (var fileStreamf = (FileStream)_fileSystem.FileInfo.FromFileName(fileTo).Open(FileMode.Create, FileAccess.Write))
{
fileStreamBack.CopyTo(fileStreamf); // Use the .Net
fileStreamBack.Flush(); // Making sure
fileStreamBack.Close(); // Making sure
}
There is also a MockFileStream object in the System.IO.Abstractions.TestingHelpers (for our convenience!)