Monday, 15 March 2010

Simulating 'access denied' for a file in C# / Windows -



Simulating 'access denied' for a file in C# / Windows -

i'm attempting write integration tests little c# routine, reads different files.

and, well, accidentally thought great have test, specifies behavior case when access file denied.

does know nice , simple way simulate in test sandbox?

i suspect emulated using directorysecurity, however, i'm not sure if it's possible correctly cases:

assume that, example, can strip access rules current user, running tests (and require uac / elevation).

i guess in case i'd lose ability restore these rights , dispose sandbox correctly after test finished (without diving stuff impersonation , access token manipulations).

i moles or other mock-based approach, i'm more interested in general solution (for example, reuse test native application).

what missing? simple way this?

you don't want acheive via security settings, instead, why not exclusive access file somewhere else?

using(file.open(path, filemode.open, fileaccess.readwrite, fileshare.none)) { //hold here maintain file locked }

c# windows file testing

No comments:

Post a Comment