Hi,
We have the following unit test which has started failing since we updated the solution to .Net 4.5 :
var underTest = new SingleSignOnAuthenticationModule();
MockObject<HttpApplication> applicationMock = MockManager.MockObject<HttpApplication>();
MockObject<HttpContext> httpContextMock = MockManager.MockObject<HttpContext>();
applicationMock.ExpectGetAlways("Context", httpContextMock.Object);
MockObject<HttpRequest> httpRequestMock = MockManager.MockObject<HttpRequest>();
httpContextMock.ExpectGetAlways("Request", httpRequestMock.Object);
var cookies = new HttpCookieCollection();
cookies.Add(new HttpCookie("MySSOCookie", token));
httpRequestMock.ExpectGetAlways("Cookies", cookies);
MockedEvent authenticateRequestHandler = applicationMock.ExpectAddEvent("AuthenticateRequest");
underTest.Init(applicationMock.Object);
authenticateRequestHandler.Fire(applicationMock.Object, EventArgs.Empty);
****SNIP******
At this point, it fires into the Single Sign On module, which runs this code :
private void SignIn(SsoUserDetails user)
{
var ssoIdentity = new SingleSignOnIdentity(user);
var ssoPrincipal = new SingleSignOnPrincipal(ssoIdentity);
_context.User = ssoPrincipal; ----- THIS LINE FAILS
Thread.CurrentPrincipal = ssoPrincipal;
}
All well and good to this point, except when it hits the line _context.User = ssoPrincipal.
ssoPrincipal is set to a valid object - but when it attempts to assign it to _context.User, or indeed you even interrogate _context.User - it throws a null reference exception.
My only thoughts at this stage are that User is a protected property, [SecurityPermission(SecurityAction.Demand, ControlPrincipal=true)], and in v4 changes were introduced to the security model.
Would this be why the MockManager is causing this to fail? I'd rather this test was using the Typemock model, but we don't have time to rewrite it as it's a fairly large test.
Any input very much appreciated!
Tony