title: Unit test AuthorizationHandler
body: <p>I used the resource-based authorization pattern in .NET Core 2.1 as described <a href="https://docs.microsoft.com/en-us/aspnet/core/security/authorization/resourcebased?view=aspnetcore-2.1&amp;tabs=aspnetcore2x" rel="nofollow noreferrer">here</a>. The only problem that I have is I have no idea how to test my <code>AuthorizationHandler</code> cleanly.</p>
  <p>Anyone here done something like that already?</p>
  <p><code>AuthorizationHandler</code> sample (from the above link):</p>
  <pre><code>public class DocumentAuthorizationHandler : 
      AuthorizationHandler&lt;SameAuthorRequirement, Document&gt;
  {
      protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
                                                     SameAuthorRequirement requirement,
                                                     Document resource)
      {
          if (context.User.Identity?.Name == resource.Author)
          {
              context.Succeed(requirement);
          }
  
          return Task.CompletedTask;
      }
  }
  
  public class SameAuthorRequirement : IAuthorizationRequirement { }
  </code></pre>