Could you please help me with writing UnitTest for this method? I tried a couple of ways but I could not solve it.
public ActionResult ChangePass()
{
if (Request.IsAuthenticated)
{
return View();
}
else
{
return RedirectToAction("Index", "Index", new { area = "" });
}
}
Here is what I am trying to do.
[TestMethod]
public void ChangePass()
{
var identity = new GenericIdentity("admin@gmail.com");
var controller = new ProfilePageController();
var controllerContext = new Mock<ControllerContext>();
var principal = new Mock<IPrincipal>();
principal.Setup(p => p.IsInRole("user")).Returns(true);
principal.SetupGet(x => x.Identity.Name).Returns("admin@gmail.com");
controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
controller.ControllerContext = controllerContext.Object;
NUnit.Framework.Assert.AreEqual(controller.ChangePass(), identity.Name);
}