I don't see a resolution to that, though, and I'm running into the
same issue.
If I run the test class below in NUnit 2.5.2, both tests pass. If I
run it in 2.5.3, the second test to run fails.
Obviously, this is a very contrived example, but it's the simplest
equivalent I have for the more complicated code in the real project
that I'm working on.
Is this as-designed? To use NUnit 2.5.3+, do we need to change our
tests so that if we have code like this, we need to have the
Thread.CurrentPrincipal assignment in SetUp instead of
TestFixtureSetUp?
Thanks in advance,
Amy
using System.Security.Principal;
using System.Threading;
using NUnit.Framework;
namespace ThreadStateTest
{
[TestFixture]
public class ThreadIdentityTest2
{
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
var identity = new GenericIdentity("foo");
Thread.CurrentPrincipal = new GenericPrincipal(identity,
new string[0]);
}
[Test]
public void Test1()
{
Assert.AreEqual("foo",
Thread.CurrentPrincipal.Identity.Name);
}
[Test]
public void Test2()
{
Assert.AreEqual("foo",
Thread.CurrentPrincipal.Identity.Name);
}
}
}
--
You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
To post to this group, send email to nunit-...@googlegroups.com.
To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
From: nunit-...@googlegroups.com [mailto:nunit-...@googlegroups.com] On Behalf Of Simone Busoli
Sent: Monday, February 08, 2010 12:52 PM
To: nunit-...@googlegroups.com
Subject: Re: [nunit-discuss] Thread.CurrentPrincipal Set In TestFixtureSetUp Not Maintained Between Tests
Generally each individual test's principal doesn't need to be
different. We have a system we're testing where you need to be "logged
in" to perform many actions, where if there's no HttpContext, logging
in consists of setting Thread.CurrentPrincipal. We have a lot of tests
around the actions where we're more interested in testing the action
itself than in testing the part about being logged in. And the way we
took care of that in many of our tests was just by logging in as a
default user in TFSU.
I'm not saying that was the best way to do it, it's just what
happened.
I found that when I recently upgraded to 2.5.3, I started getting
failures due to not being "logged in." So, I isolated and simplified
the problem to the code I posted.
Although I never used 2.5.2 in day-to-day use, I did grab it and check
that it didn't happen there, so it seems to be related to a change in
2.5.3. I thought it might be related to the bug fix "Thread principal
is now saved before each test and restored afterward eliminating
failures under .NET 4.0." that's listed in the release notes at
http://nunit.com/index.php?p=releaseNotes&r=2.5.3.
I'd have to go back and check again, but when I was playing with it, I
tried writing out the thread's ID in each test, and I thought it
actually was the same, which I thought maybe meant that the tests were
executing on the same thread. But I should probably play with that
more.
Anyway, I can work on changing our tests not to rely on "logging in"
in TFSU, I just wasn't sure if I needed to, or if it might be a bug in
NUnit that would get fixed, rather than expected behaviour.
And sure, I'll add a bug report on launchpad.
Thanks all,
Amy
On 9 Feb, 06:58, Simone Busoli <simone.bus...@gmail.com> wrote:
> Yes, please Amy, file a bug report on launchpad about this issue.
>
On 9 Feb, 19:02, Amy Thorne <amygilchr...@gmail.com> wrote:
> Whoops, I looked away for a couple days and suddenly help came to the
> rescue :-)
>
> Generally each individual test's principal doesn't need to be
> different. We have a system we're testing where you need to be "logged
> in" to perform many actions, where if there's no HttpContext, logging
> in consists of setting Thread.CurrentPrincipal. We have a lot of tests
> around the actions where we're more interested in testing the action
> itself than in testing the part about being logged in. And the way we
> took care of that in many of our tests was just by logging in as a
> default user in TFSU.
>
> I'm not saying that was the best way to do it, it's just what
> happened.
>
> I found that when I recently upgraded to 2.5.3, I started getting
> failures due to not being "logged in." So, I isolated and simplified
> the problem to the code I posted.
>
> Although I never used 2.5.2 in day-to-day use, I did grab it and check
> that it didn't happen there, so it seems to be related to a change in
> 2.5.3. I thought it might be related to the bug fix "Thread principal
> is now saved before each test and restored afterward eliminating
> failures under .NET 4.0." that's listed in the release notes athttp://nunit.com/index.php?p=releaseNotes&r=2.5.3.
> -----Original Message-----
> From: nunit-...@googlegroups.com
> [mailto:nunit-...@googlegroups.com] On Behalf Of Amy Thorne
> Sent: Wednesday, February 10, 2010 8:10 AM
> To: NUnit-Discuss
> Subject: [nunit-discuss] Re: Thread.CurrentPrincipal Set In
> TestFixtureSetUp Not Maintained Between Tests
>