No more System.IO.File

If you are working with .Net and you need to read/write files you may be familiar with the System.IO.File class which provides many methods to manipulate files. But there is an issue with that class: its methods are static and because of that you won’t be able to mock it*.

After dealing with this situation for several years and using always a very similar strategy, I finally decided to create a reusable component to encapsulate the System.IO.File class.

The component I created is called System.IO.Utilities, its code is available on Github and it is also published on NuGet, ready for you to use it. At this moment it just provides an interface with one implementation that wraps the System.IO.File class.

Here you can see how to use it.

Contributions are welcome 😉

(*to be more precise: you won’t be able to mock that class with proxy-based mocking tool like Moq, but you can still mock it with «lower-level» tool like TypeMock)

Deja una respuesta

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.