Abstraction for the .Net Filesystem classes
Wrappers for some common classes from System.IO Namespace to create a layer of abstraction
Current abstractions of System.IO
- Directory
- File
- Path
Instead of using the Namespace System.IO include the Namespace Abstract.FileSystem to use Directory or File.
Abstract.FileSystem.Directory and Abstract.FileSystem.File both have a Factory Property. This can be set through the static method Setup(Func<IFileService> service) or Setup(Func<IDirectoryService> service). The Interface IFileService and IDirectoryService both provide the abstraction layers.
_service = new Mock<IDirectoryService>();
Directory.Setup(() => _service.Object);
Now all Access to Abstract.FileSystem.Directory use the Mock of IDirectoryServerice
Path behaviour on Linux differs from Windows. For this reason there is a class for SystemPath that manages paths depending on the system that is run on.
var path = (SystemPath)"Test" / "Path";
path.ToString();
On a Windows this results in
Test\Path
while on a Unix system the result looks different
Test/Path