title: Is there a way to have a SetUpFixture that runs once per class instead of once per namespace?
body: <p><strong>Scenario</strong><br />
  First of all, I'm new to testing - so please bear with me. Inside of my <em>test project</em>, there is a Controllers folder. The Controllers folder may contain a ControllerATest.cs, ControllerBTest.cs, and ControllerCTest.cs. Because my namespace aligns with my folder structure, they all share the namespace MyProject.Tests.Controllers.</p>
  
  <p>From what I've read in the <a href="http://www.nunit.org/index.php?p=setupFixture&amp;r=2.4">NUnit SetUpFixture Documentation</a>, a [SetUpFixture] inside this namespace will run once <em>for the entire namespace</em>. That is, if I run all of my controller tests at once - the SetUpFixture will be executed only once.</p>
  
  <p><strong>Problem</strong><br />
  As I said, each controller test shares a namespace. SetUpFixtures apply to the entire namespace. What if I want each controller to have their <em>own</em> SetUpFixture? This is a problem when SetUpFixtures apply to entire namespaces. What I want is something that executes once, and not per-test. One of the things I do inside my SetUpFixture's SetUp is instantiate a controller. Sure, I could instantiate all 3 controllers in the SetUpFixture, but this seems ugly when maybe I am only testing ControllerC. That really doesn't seem clean. Therefore, I would like a SetUpFixture that applies <em>only</em> to the class it appears in, such as ControllerCTests.</p>
  
  <p>From what I've read, this specific functionality seems to be impossible with NUnit. And if it's not possible with NUnit, that makes me think it's not a common scenario. And if it's not a common scenario, I am doing something wrong. My question is, what? Maybe my testing structure is off and it needs to change. Or maybe it <em>is</em> possible with NUnit?</p>
  
  <p><strong>Code</strong><br />
  An example of my desired structure:</p>
  
  <pre><code>namespace MyProject.Tests.Controllers
  {
  public class ControllerATests
  {
      private static IMyProjectRepository _fakeRepository;
      private static ControllerA _controllerA;
  
      [SetUpFixture]
      public class before_tests_run
      {
          [SetUp]
          public void ControllerASetup()
          {
              _fakeRepository = FakeRepository.Create();
  
              _controllerA = new ControllerA(_fakeRepository);
          }
      }
  
      [TestFixture]
      public class when_ControllerA_index_get_action_executes
      {
          [Test]
          public void it_does_something()
          {
              //
          }
  
          [Test]
          public void it_does_something_else()
          {
              //
          }
      }
  }
  
  public class ControllerBTests
  {
      private static IMyProjectRepository _fakeRepository;
      private static ControllerB _controllerB;
  
      [SetUpFixture]
      public class before_tests_run
      {
          [SetUp]
          public void ControllerBSetup()
          {
              _fakeRepository = FakeRepository.Create();
  
              _controllerB = new ControllerB(_fakeRepository);
          }
      }
  
      [TestFixture]
      public class when_ControllerB_index_get_action_executes
      {
          [Test]
          public void it_does_something()
          {
              //
          }
  
          [Test]
          public void it_does_something_else()
          {
              //
          }
      }
  }
  }    
  </code></pre>
  
  <p><strong>Things I've Tried</strong><br /></p>
  
  <ul>
  <li>Moving each .cs file into its own folder, so they have different namespaces. Technically this solves the problem, it just seems a little ugly to have a bunch of subfolders with only 1 item in each of them. Ugly, and will no longer match my parent project's structure which I was going for. But - maybe this is the way to go.</li>
  <li>Not instantiating my controller in the <em>SetUpFixture</em> SetUp, and instead doing it in the <em>TestFixture</em> SetUp so that a new one gets instantiated for every test (ex: 5 tests = 5 separate instances) instead of once per class or namespace. Though it seems like if I can get away with only creating 1 instance, I should.</li>
  </ul>
  
  <p>Suggestions?</p>