robertc
robertc

Reputation: 75747

How can I locally debug file permission issues in Visual Studio?

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?

Upvotes: 1

Views: 432

Answers (1)

ChrisF
ChrisF

Reputation: 137158

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.

Upvotes: 1

Related Questions