I need to create Unit Tests for an ASP.NET MVC 2.0 web site. The site uses Windows Authentication.
I\'ve been reading up on the necessity to mock the HTTP context
To mock WindowsIdentity you can do the following:
var mockedPrincipal = new Mock(WindowsIdentity.GetCurrent());
mockedPrincipal.SetupGet(x => x.Identity.IsAuthenticated).Returns(true);
mockedPrincipal.SetupGet(x => x.Identity.Name).Returns("Domain\\User1");
mockedPrincipal.Setup(x => x.IsInRole("Domain\\Group1")).Returns(true);
mockedPrincipal.Setup(x => x.IsInRole("Domain\\Group2")).Returns(false);
then use mockedPrincipal.Object to get the actual WindowsIdentity