title: moq and the "as" keyword
body: <p>I'm attempting to provide a mock that will help me test:</p>
  
  <pre><code>ClaimsPrincipal princple = Thread.CurrentPrincipal as ClaimsPrincipal;
  </code></pre>
  
  <p>However from what I can tell, the "as" keyword returns null even though I can see in the debugger Thread.CurrentPrincipal is the mock.</p>
  
  <p>To test the theory I put together this short demo:</p>
  
  <pre><code>void Main()
  {
      var userMock = new Mock&lt;IUser&gt;();
      userMock.Setup(w =&gt; w.UserId).Returns(1);
  
      var user = userMock.Object as User;
  
      user.Dump(); // null
  
  }
  
  public interface IUser
  {
      int UserId { get; set; }
  }
  
  public class User : IUser
  {
      public int UserId { get; set; }
  }
  </code></pre>
  
  <p>How can I provide moq's for code that use the as keyword in the background?</p>
  
  <p>From what I understand perhaps I need to provide a way for the proxy to cast back?</p>
  
  <p>I sort of realise that this isn't possible, but wondered what people's approaches are to solving this.</p>