File and File Container Wrapper Library on CodePlex

Sometime ago we were talking about file wrappers and testing these things on the ALT.NET mailing list. It's a rather boring task to test say a file system without actually writing files (which you might not want to do). Wouldn't it be nice to have a wrapper around a file system so a) you could forget about writing one yourself and b) you could throw something at Rhino mocks because you really don't want to test writing files.

I've put together a project implementing this and it's now released on CodePlex. It's composed of interfaces (IFile and IFileContainer) that provide abstractions over whatever kind of file or file container you want. This allows you to wrap up a file system (indivdual files or containers of files like folders) and test them accordingly. Concrete implementations can be injected via a Dependency Injection tool and you can sit back and forget about the rigors of testing file access.

There are 3 concrete implementations (found in FileStrategyLib.dll) that implement a file system (IFile), folders (IFileContainer), and zip files (IFileContainer using SharpZipLib). There's also a test project with a whopping 10 unit tests (providing 97% coverage, darn) included. More documentation and sample code is available on the CodePlex site.

You can check out the project here on CodePlex:
http://www.codeplex.com/ifilecontainer

1.0 is available and released under the MIT License. It contains the binary and source distributions. I'll check the code into the source repository later tonight.

Note that this is a very simple library concisting of 2 interfaces and about 50 lines of code. Of course being an open source project I encourage you to check it out and enhance it if you want. It's not the be-all system to get all kinds of information out but should get you started. It was originally written just for a simple system to create and add files to a folder and zip file but can be extended. Otherwise, consider it an example of having to wrap and test a system like a file system which you may run into from time to time.

Enjoy!

Update: Source code tree is checked in and posted now.

5 Comments

Comments have been disabled for this content.