Mocking the file system

time to read 1 min | 94 words

I have the following piece of code:

image

And I wasn't sure about how I can test this thing. For production, this will use a File Stream, and getting those to produce errors is non trivial in most situations. A bit of thinking, however, told me that I can write a test for the error handling section of this fairly easily, like this:

 

image

I love having powerful tools at my reach.