views:

10

answers:

1

I want to debug an ASP.Net website as it attempts to write a file to a directory.

When actually deployed this file would possibly not be writeable by the worker process so an error would be thrown, this is not a problem as I just want to catch the error, inform the user and move on.

Of course, if I'm debugging on my local machine then I'm an administrator and I have permission to write to the file, so I can't check that I've trapped the correct errors and I can't step through an see where it goes wrong if I haven't. Is there a standard approach to this sort of thing?

+1  A: 

You could replace the file writing methods with mock methods that you can modify to return the desired values (or raise the appropriate exception).

Look into mocking frameworks.

Another solution could be to temporarily remove your write permissions from those folders. You still have full control so you can put the rights back after you've finished testing.

ChrisF
Changing the permissions worked. Issue turned out to be another bit of code incorrectly re-raising the exception, which I wouldn't have noticed if I wasn't debugging :)
robertc