title: Is it possible to write a test that can test an AuthorizationPolicy Object?
body: <p>I've got a policy that I want to test in C#</p>
  
  <pre><code>public class WorkflowCreatePolicy
  {
      public AuthorizationPolicy AuthorizationPolicy =&gt;
          new AuthorizationPolicyBuilder()
              .RequireClaim("scope", "WorkflowAdmin")
              .Build();
  }
  </code></pre>
  
  <p>Does anyone know of a way to test the AuthorizationPolicy to confirm that the scope "WorkflowAdmin" is successful and all others aren't?</p>
  
  <p>This is what I see when I inspect the object:</p>
  
  <p><a href="https://i.stack.imgur.com/XRpQI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XRpQI.png" alt="enter image description here"></a></p>
  
  <p>I've managed to find this website: <a href="http://blog.stoverud.no/posts/how-to-unit-test-asp-net-core-authorizationhandler/" rel="nofollow noreferrer">Authorization Handler Unit Tests</a> but its talking about testing handlers and has code that marks the auth attempt as successful.</p>
  
  <p>i'm not sure if this is getting close or not.  It currently doesn't pass</p>
  
  <pre><code>[Test]
  public void GivenPolicyName_WhenICallPolicyChecks_ThenItPasses()
  {
      ClaimsPrincipal user = new ClaimsPrincipal(new ClaimsIdentity(new List&lt;Claim&gt; { new Claim(CustomClaims.Scope, "WorkflowAdmin") }));
  
      WorkflowCreatePolicy workflowCreatePolicy = new WorkflowCreatePolicy();
  
      AuthorizationHandlerContext authorizationHandlerContext = new AuthorizationHandlerContext(workflowCreatePolicy.AuthorizationPolicy.Requirements, user, null);
  
      Assert.That(authorizationHandlerContext.HasSucceeded, Is.EqualTo(true));
  }
  </code></pre>