Skip to content

MockFileSystem extensions #32

Description

@rcdailey

Would you find the below extension methods useful? If so, I am happy to open a pull request. I'm hesitant to do so right away because I'm not sure if these should be extension methods in this library or if I should contribute them as actual class members upstream (upstream being the actual IO.Abstractions package).

I found these extension methods to be absolutely invaluable in my own code base in conjunction with the Extensions package. It eliminates a lot of boilerplate in my unit tests, namely these:

varfs=newMockFileSystem();varmyDir=fs.CurrentDirectory().SubDirectory("dir");varmyFile=fs.CurrentDirectory().File("file.txt");// Creating empty filesfs.AddFile(myFile.FullName,newMockFileData(""));// Becomesfs.AddEmptyFile(foo);// Specifying `FullName` all over the place...fs.AddDirectory(myDir.FullName);// Becomesfs.AddDirectory(myDir);

If you could provide some guidance and feedback, I'm happy to move this to a PR. Thanks for your time!

publicstaticclassMockFileSystemExtensions{publicstaticvoidAddEmptyFile(thisMockFileSystemfs,stringpath){fs.AddFile(path,newMockFileData(""));}publicstaticvoidAddEmptyFile(thisMockFileSystemfs,IFileInfopath){fs.AddEmptyFile(path.FullName);}publicstaticvoidAddDirectory(thisMockFileSystemfs,IDirectoryInfopath){fs.AddDirectory(path.FullName);}publicstaticvoidAddFile(thisMockFileSystemfs,IFileInfopath,MockFileDatadata){fs.AddFile(path.FullName,data);}publicstaticMockFileDataGetFile(thisMockFileSystemfs,IFileInfopath){returnfs.GetFile(path.FullName);}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions