title: Castle interceptor does not intercept a method on an MVC Controller during unit test
body: <p>I have a .net test class. In the Initialize method, I create a windsor container and make some registrations. In the actual test method, I call a method on the controller class but the interceptor does not work and the method gets directly called. What are potential reasons for this?</p>
  
  <p>Here is all the related code:</p>
  
  <p>Test.cs:</p>
  
  <pre><code>private SomeController _someController;
  
  [TestInitialize]
  public void Initialize()
  {
      Container.Register(Component.For&lt;SomeInterceptor&gt;());
      Container.Register(
          Component.For&lt;SomeController&gt;()
              .ImplementedBy&lt;SomeController&gt;()
              .Interceptors(InterceptorReference.ForType&lt;SomeInterceptor&gt;())
              .SelectedWith(new DefaultInterceptorSelector())
              .Anywhere);
  
      _someController = Container.Resolve&lt;SomeController&gt;();
  }
  
  [TestMethod]
  public void Should_Do_Something()
  {
      _someController.SomeMethod(new SomeParameter());
  }
  </code></pre>
  
  <p>SomeController.cs:</p>
  
  <pre><code>[HttpPost]
  public JsonResult SomeMethod(SomeParameter parameter)
  {
      throw new Exception("Hello");
  }
  </code></pre>
  
  <p>SomeInterceptor.cs:</p>
  
  <pre><code>public class SomeInterceptor : IInterceptor
  {
      public void Intercept(IInvocation invocation)
      {
          // This does not gets called in test but gets called in production
  
          try
          {
              invocation.Proceed();
          }
          catch
          {
              invocation.ReturnValue = new SomeClass();
          }
      }
  }
  </code></pre>
  
  <p>DefaultInterceptorSelector.cs:</p>
  
  <pre><code>public class DefaultInterceptorSelector : IInterceptorSelector
  {
      public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
      {
          return 
              method.ReturnType == typeof(JsonResult) 
              ? interceptors 
              : interceptors.Where(x =&gt;  !(x is SomeInterceptor)).ToArray();
      }
  }
  </code></pre>