title: How do I make this ASP.NET MVC controller more testable?
body: <p>I have a controller that overrides <code>OnActionExecuting</code> and does something like this:</p>
  
  <pre><code>protected override void OnActionExecuting(ActionExecutingContext filterContext)
  {
      base.OnActionExecuting(filterContext);
      string tenantDomain = filterContext.RouteData.Values["tenantDomain"] as string;
      if (!string.IsNullOrWhiteSpace(tenantDomain))
      {
          using (var tx = BeginTransaction())
          {
              this.Tenant = repo.FindOne(t =&gt; t.Domain == tenantDomain);
          }
      }
  }
  </code></pre>
  
  <p><code>Tenant</code> is a protected property with a private setter. The class itself is an abstract base controller that my real controllers derive from. I have code in other controllers that looks a lot like this:</p>
  
  <pre><code>if (Tenant == null)
  {
     // Do something
  }
  else
  {
     // Do something else
  }
  </code></pre>
  
  <p>How do I test this code? What I need to do is to somehow set the Tenant property, but I can't because:</p>
  
  <ol>
  <li>It's a protected property, and</li>
  <li>It has a private setter</li>
  </ol>
  
  <p>Changing the visibility of <code>Tenant</code> doesn't "feel" right. What are my alternatives to unit test my derived controllers?</p>