How to add claims in a mock ClaimsPrincipal : <p>I am trying to unit test my controller code which gets the information from the ClaimsPrincipal.Current. 
In the controller code I</p>

<pre><code>public class HomeController {
    public ActionResult GetName() {
        return Content(ClaimsPrincipal.Current.FindFirst("name").Value);
    }
}
</code></pre>

<p>And I am trying to mock my ClaimsPrincipal with claims but I still don't have any mock value from the claim.</p>

<pre><code>// Arrange
IList&lt;Claim&gt; claimCollection = new List&lt;Claim&gt;
{
    new Claim("name", "John Doe")
};

var identityMock = new Mock&lt;ClaimsIdentity&gt;();
identityMock.Setup(x =&gt; x.Claims).Returns(claimCollection);

var cp = new Mock&lt;ClaimsPrincipal&gt;();
cp.Setup(m =&gt; m.HasClaim(It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;())).Returns(true);
cp.Setup(m =&gt; m.Identity).Returns(identityMock.Object);

var sut = new HomeController();

var contextMock = new Mock&lt;HttpContextBase&gt;();
contextMock.Setup(ctx =&gt; ctx.User).Returns(cp.Object);

var controllerContextMock = new Mock&lt;ControllerContext&gt;();
controllerContextMock.Setup(con =&gt; con.HttpContext).Returns(contextMock.Object);
controllerContextMock.Setup(con =&gt; con.HttpContext.User).Returns(cp.Object);

sut.ControllerContext = controllerContextMock.Object;

// Act
var viewresult = sut.GetName() as ContentResult;

// Assert
Assert.That(viewresult.Content, Is.EqualTo("John Doe"));
</code></pre>

<p>The viewresult.Content is empty as I run the unit test. Any help if I can add the mock claim. Thanks.</p>
