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)

Anuncios

Responder

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. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s