Unit Testing Microsoft Enterprise Library Security Block using NUnit GUI

Topics: Enterprise Library Core, Security Application Block
Jul 27, 2009 at 7:04 PM

I'm using the Microsoft Enterprise Library's security block (EntLib version 4.1), specifically the library's support for authorization using AzMan as the authorization provider. I'm using impersonation (WindowsIdentity.Impersonate()) in my NUnit tests to impersonate test accounts with various levels of authorization. Everything works as expected when I launch an NUnit test from the right-click context menu (TestDriven). However, when I try to run the test from the NUnit GUI it fails with the following error:

System.IO.FileLoadException : Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Access is denied.

The above error only occurs when I'm impersonating a test user while running the test using the NUnit GUI. The test users are domain accounts. All domain accounts are included in the local Users group on my development machine.

More interesting facts:

If I put the test users in the local Administrators group the tests run fine from the NUnit GUI, but obviously this is not desirable.

If I access the method under test by actually running the application and logging in (Windows authentication) as one of the test users everything works as expected.

As stated above, if I run the test from the right-click context menu it works fine.

My development machine is Windows XP SP3. I have the AzMan 1.2 primary interop assembly installed and registered in the GAC.

The error occurs as soon as I reference the EntLib security block with the following line:

IAuthorizationProvider authorizationProvider = AuthorizationFactory.GetAuthorizationProvider();

Jul 28, 2009 at 6:43 AM

I'm surprised you can get it to work at all. Entlib uses MSTest, not NUnit. I guess NUnitGUI has grown some more features since I last looked at it. TestDriven.NET is it's own, separate runner, so I'm not surprised there's a difference in behavior.