Ok, so after cobbling together help from a few older links (i.e. Setting HttpContext.Current.Session in a unit test) I was able to get this working, thought I would post it here for posterity:
public class ContextHelper
{
public static HttpContext GetMockedHttpContext()
{
var context = new Mock<HttpContext>();
var identity = new Mock<IIdentity>();
var contextUser = new Mock<ClaimsPrincipal>();
contextUser.Setup(ctx => ctx.Identity).Returns(identity.Object);
identity.Setup(id => id.IsAuthenticated).Returns(true);
identity.Setup(id => id.Name).Returns("validemail@test.com");
context.Setup(x => x.User).Returns(contextUser.Object);
return context.Object;
}
}
This allows my unit tests to pull out the user name of my fake user easily.
I call it like this:
var uc = new UserController();
uc.ControllerContext.HttpContext = ContextHelper.GetMockedHttpContext();
uc.WhateverMethodGoesHere();