I want to wrap a piece of code that uses the Windows implementation API in a neat little helper class, and, as usual, I'm looking for a way to pass the test first. However, although WindowsIdentity is a managed class, the LogonUser call, which is required to actually log on as another user, is an unmanaged function in the advapi32.dll file.
I think I can get around this by introducing an interface for my helper class to use and hide P / Invoke calls in the implementation, but testing this implementation will still be a problem. And you can imagine that the actual implementation of the impersonation in the test can be a bit problematic, given that the user really must exist in the system.
source
share