Reading through the existing unit testing related threads here on Stack Overflow, I couldn\'t find one with a clear answer about how to unit test file I/O operations. I have
Since 2012, you can do that using Microsoft Fakes without the need to change your codebase for example because it was frozen already.
First generate a fake assembly for System.dll - or any other package and then mock expected returns as in:
using Microsoft.QualityTools.Testing.Fakes;
...
using (ShimsContext.Create())
{
System.IO.Fakes.ShimFile.ExistsString = (p) => true;
System.IO.Fakes.ShimFile.ReadAllTextString = (p) => "your file content";
//Your methods to test
}