title: Correct Way To Run Test Set Up with Nunit TestCaseSource
body: <p>I am trying to run multiple tests using TestCaseSource in NUnit. But I am struggling to get the [SetUp] to run when I want it.</p>
  
  <p>At the moment it works how I want it to but it doesnt feel "right". So the following is the main test case code (simplified):</p>
  
  <pre><code>public class ImportTestCases
  {
  
      ImportTestCases()
      {
          TestData.RunTestSetup();
      }
  
      public static IEnumerable TestCases
      {
          get
          {
              //run the funciton under test...
              var results = RunFunctionSubjectToTest(TestData.ImportantVar);
  
              //get multiple results...
              var allProperties =new TestCaseData(o).Returns(true)
                  ExpandNestedProperties(results.AllProperties)
                      .ToList()
                      .ConvertAll(o =&gt; new TestCaseData(o).Returns(true));
  
              return allProperties;
          }
      }
  
  
  }
  
  
  [TestFixture]
  public class ImportTests
  {
  
      [TestFixtureSetUp]
      public void ImporTestSetup()
      {
          TestData.RunTestSetup();
      }
  
      [Test, TestCaseSource(typeof(ImportTestCases), nameof(ImportTestCases.TestCases))]
      public bool PropertyTest(UnitTestHelper.PropInfo info)
      {
          return info.DoTheyMatch;
      }
  
  }
  </code></pre>
  
  <p>The trouble here is that [SetUp] does not run before ImportTestCases "TestCases" 
  property "get" is ran. The Constructor of "ImportTestCases" is not ran either. So in order to ensure "RunTestSetup" is ran before ImportVar is referenced I have to do the following:</p>
  
  <pre><code>public static class TestData
  {
      private static bool HasSetUpRan = false;
      private static int _importantVar;
      public static int ImportantVar
      {
          get
          {
              if(!HasSetUpRan)
              {
                  RunTestSetup();
              }
              return _importantVar;
          }
      }        
      public static void RunTestSetup()
      {
          if (HasSetUpRan)
          {
              return;
          }
          ///do set up
          //e.g. _importantVar = GenerateId();
          //end
          HasSetUpRan= true;
      }
  
  }
  </code></pre>
  
  <p>As you can see this ensures that Set up has ran before the variable is returned. Sadly this is the only way I have managed to get it to work so far. Which as I say feels "wrong" and over complicated. Perhaps I am overusing testCases here? or I should use some kind of paramatised testcase (is that possible?). </p>
  
  <p>I have tried to simplify the code above so apologies if it simply doesnt make sense what I am trying to test. </p>
  
  <p>The main point <strong>is is there a [Setup] that runs before TestCaseSources are created?</strong></p>