I have a few questions about this. 1) SetPrincipalPolicy effects the entire domain. That means it would effect all the tests in that domain, not just some tests. Is this your intent? Is so, the call belongs in a SetUpFixture that will be executed before all tests, not in a single test.
2) NUnit does not set CurrentPrincipal before running a test. It merely accesses and saves it, restoring it after the test. If that's a problem, we could add a check to only reset it if it has been changed. Will this work for you? The intention is to make it impossible for a single test to change the environment under which other tests run. 3) Have you run your example test as the _only_ test in an assembly? That would give the best information about what is going on. Charlie On Wed, Feb 2, 2011 at 2:22 PM, John Rusk <[email protected]> wrote: > Public bug reported: > > I have some unit tests that call AppDomain.SetPrinicipalPolicy (in order > to run tests using a Windows Principal). > > Unfortunately, SetPrincipalPolicy doesn't work in tests run from the > NUnit 2.5.9 GUI runner. (It does work, just fine, from the NUnit 2.4.3 > GUI Runner). > > Here is a unit test to demonstrate the problem. The test passes (as it > should) in UNnit 2.4.3, but fails in 2.5.9: > > [Test] > public void CanSetPrincipalPolicy() > { > > AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); > Assert.That(Thread.CurrentPrincipal is WindowsPrincipal); > } > > The problem appears to be the fact that NUnit's TestExecutionContext is > accessing Thread.CurrentPrincipal before the test runs. As per the > documentation for SetPrincipalPolicy, it _doesn't work_ if > Thread.CurrentPrincipal has been used _before_ SetPrincipalPolicy. > > If this cannot be solved, then can a workaround pls be suggested. E.g. > - something in a nUnit config file to set principal policy, OR > - a documented way to execute SetPrincipalPolicy, in the same AppDomain as > the tests, before TestExecutionContext touches Thread.CurrentPrincipal. > Is there any way to have code, in NUnit, that runs in the same app domain as > the tests, but BEFORE > > ** Affects: nunitv2 > Importance: Undecided > Status: New > > -- > You received this bug notification because you are a member of NUnit > Developers, which is subscribed to NUnit V2. > https://bugs.launchpad.net/bugs/712156 > > Title: > Tests cannot use AppDomain.SetPrincipalPolicy > -- You received this bug notification because you are a member of NUnit Developers, which is subscribed to NUnit V2. https://bugs.launchpad.net/bugs/712156 Title: Tests cannot use AppDomain.SetPrincipalPolicy Status in NUnit V2 Test Framework: New Bug description: I have some unit tests that call AppDomain.SetPrinicipalPolicy (in order to run tests using a Windows Principal). Unfortunately, SetPrincipalPolicy doesn't work in tests run from the NUnit 2.5.9 GUI runner. (It does work, just fine, from the NUnit 2.4.3 GUI Runner). Here is a unit test to demonstrate the problem. The test passes (as it should) in UNnit 2.4.3, but fails in 2.5.9: [Test] public void CanSetPrincipalPolicy() { AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); Assert.That(Thread.CurrentPrincipal is WindowsPrincipal); } The problem appears to be the fact that NUnit's TestExecutionContext is accessing Thread.CurrentPrincipal before the test runs. As per the documentation for SetPrincipalPolicy, it _doesn't work_ if Thread.CurrentPrincipal has been used _before_ SetPrincipalPolicy. If this cannot be solved, then can a workaround pls be suggested. E.g. - something in a nUnit config file to set principal policy, OR - a documented way to execute SetPrincipalPolicy, in the same AppDomain as the tests, before TestExecutionContext touches Thread.CurrentPrincipal. Is there any way to have code, in NUnit, that runs in the same app domain as the tests, but BEFORE _______________________________________________ Mailing list: https://launchpad.net/~nunit-core Post to : [email protected] Unsubscribe : https://launchpad.net/~nunit-core More help : https://help.launchpad.net/ListHelp

