How we can mock the authenticated user using Moq framework. Form Authentication used.
I need to write unit tests for the action below
public PartialV
I have used something like that, maybe it helps you:
var controllerContext = new Mock();
var principal = new Moq.Mock();
principal.Setup(p => p.IsInRole("Administrator")).Returns(true);
principal.SetupGet(x => x.Identity.Name).Returns(userName);
controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
controller.ControllerContext = controllerContext.Object;