title: How to Mock ClaimsPrincipal in unit test .net
body: <p>I am doing unit test on my controller method to information from ClaimsPrincipal object, but <code>Current.FindFirst()</code> returns nothing, can anyone help this? Thanks. (written in VB and C# is acceptable too):</p>
  
  <pre><code>  Public Class TestController
      Public Function GetEmail() As String
           Return ClaimsPrincipal.Current.FindFirst(ClaimTypes.Name).Value
      End Function
    End Class
  
  &lt;TestMethod()&gt;
  Public Sub Test()
    //Arrange
      Dim fackClaimPrinciple = New Mock(Of ClaimsPrincipal)()
      Dim claims = New List(Of Claim)() From {New Claim(ClaimTypes.Name, "user@hotmail.com")}
      fackClaimPrinciple.Setup(Function(e) e.Claims).Returns(claims)
      Thread.CurrentPrincipal = fackClaimPrinciple.[Object]
  
    // Act
    Dim result = TestController.GetEmail()
  
    '... ClaimsPrincipal.Current.FindFirst(ClaimTypes.Name).Value Returns nothing??
  
  End Sub
  </code></pre>