Tuesday, November 25, 2008 2:19 PMHi
Could someone point me to an article or advise me how to set the windows identity in my unit tests. I am testing some code that needs to grab the windows principal but when I test it using VSTS the Thread.CurrentPrincipal is already set to a generic principal. I could seem to find any documentation on how to control this so any help appreciated. (I've tried setting the app domain principal policy in code to no effect - I think it has already been set to generic principal by the unit test framework code?).
Thursday, November 27, 2008 2:51 AMHi Adrian,
You can read here for more information about this class.
Please mark the replies as answers if they help and unmark them if they provide no help.
Wednesday, December 31, 2008 9:01 PMWere you ever successful at figuring out how to set the windows identity in the testing framework? I've got the same issue...
Thursday, January 01, 2009 1:49 PMHi
No - never solved it. However, I have some test projects where the tests run quite happily with the current users windows idenity and others (in different solutions) that show the behaviour here. My suspicion is that the problem is caused by having a WCF project in the solution with an anonomous binding but I havent had a chance to test out this theory yet.
Sunday, October 25, 2009 5:56 PMThere is a good blog post on this avaialble here:
- Proposed As Answer by Aaron KowallMVP Sunday, October 25, 2009 5:57 PM
Monday, February 28, 2011 1:22 PM
This works for me:
var identity = new GenericIdentity(WindowsIdentity.GetCurrent().Name); var principal = new GenericPrincipal(identity, null); Thread.CurrentPrincipal = principal;
Of course the principal isn't of type WindowsIdentity but I didn't need it. The actual code only uses
- Proposed As Answer by Jose DG Friday, November 23, 2012 7:24 AM
Friday, November 23, 2012 7:24 AM
Thanks a lot!
Worked like a charm!