title: Testing a TypeFilterAttribute with Dependency Injection
body: <p>I have a simple <code>TypeFilterAttribute</code>, called <code>MyFilter</code> that utilises dependency injection under the hood (.net core 2.2):</p>
  
  <pre><code>public class MyFilter : TypeFilterAttribute
  {
      public MyFilter() :
          base(typeof(MyFilterImpl))
      {
      }
  
      private class MyFilterImpl : IActionFilter
      {
          private readonly IDependency _dependency;
  
          public MyFilterImpl(IDependency injected)
          {
              _dependency = injected;
          }
  
          public void OnActionExecuting(ActionExecutingContext context)
          {
              _dependency.DoThing();
          }
  
          public void OnActionExecuted(ActionExecutedContext context)
          {
          }
      }
  }
  </code></pre>
  
  <p>I'm trying to test this with xUnit using a <code>FakeController</code> that looks like this:</p>
  
  <pre><code>[ApiController]
  [MyFilter]
  public class FakeApiController : ControllerBase
  {
      public FakeApiController()
      {
      }
  
      [HttpGet("ping/{pong}")]
      public ActionResult&lt;string&gt; Ping(string pong)
      {
          return pong;
      }
  }
  </code></pre>
  
  <p>The problem I'm having is that I don't seem to be able to trigger the <code>MyFilter</code> logic at <strong><em>test time.</em></strong> This is what my test method looks like so far:</p>
  
  <pre><code>[Fact]
  public void MyFilterTest()
  {
      IServiceCollection services = new ServiceCollection();
      services.AddScoped&lt;IDependency, InMemoryThing&gt;();
  
      var provider = services.BuildServiceProvider();
      var httpContext = new DefaultHttpContext();
  
      httpContext.RequestServices = provider;
  
      var actionContext = new ActionContext
      {
          HttpContext = httpContext,
          RouteData = new RouteData(),
          ActionDescriptor = new ControllerActionDescriptor()
      };
  
      var controller = new FakeApiController()
      {
          ControllerContext = new ControllerContext(actionContext)
      };
  
      var result = controller.Ping("hi");
  }
  </code></pre>
  
  <p>Any idea what I'm missing here?</p>
  
  <p>Thanks!</p>