title: Migration problems when migrate from NUnit 2.X to NUnit 3.X
body: <p>I'm using NUnit 2.X library but want to use NUnit 3.X now. I have some problems about migration from 2.X to 3.X. First i have a setup fixture class. Here is the 2.X version;</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Reflection;
  using HalisEnerji.QuantSignal.Logging;
  using NUnit.Framework;
  
  namespace HalisEnerji.QuantSignal.Tests
  {
      [SetUpFixture]
      public class Initialize
      {
          [SetUp]
          public void SetLogHandler()
          {
              Log.LogHandler = new ConsoleLogHandler();
          }
      }
  }
  </code></pre>
  
  <p>First problem is fixed via change "Setup" attribute with "OneTimeSetUp" attribute. Second problem fixed via add some codes for set test directory. Because i'm using Re-Sharper test engine. Here is final shape of setup fixture;</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Reflection;
  using HalisEnerji.QuantSignal.Logging;
  using NUnit.Framework;
  
  namespace HalisEnerji.QuantSignal.Tests
  {
      [SetUpFixture]
      public class Initialize
      {
          [OneTimeSetUp]
          public void SetLogHandler()
          {
              Log.LogHandler = new ConsoleLogHandler();
  
              var assembly = Assembly.GetExecutingAssembly();
              var localPath = new Uri(assembly.CodeBase).LocalPath;
              var direcotyName = Path.GetDirectoryName(localPath);
              if (direcotyName != null)
              {
                  Environment.CurrentDirectory = direcotyName;
              }
          }
      }
  }
  </code></pre>
  
  <p>Well after solve setup fixture problem, my real problems begins with use TestCaseSource/TestCaseData. Here is sample 2.X version;</p>
  
  <pre><code>[Theory]
  [TestCaseSource("CreateSymbolTestCaseData")]
  public void CreateSymbol(string ticker, Symbol expected)
  {
      Assert.AreEqual(Symbol.Create(ticker), expected);
  }
  
  private TestCaseData[] CreateSymbolTestCaseData()
  {
      return new []
      {
          new TestCaseData("SPY", new Symbol(Security.GenerateEquity("SPY"), "SPY")),
          new TestCaseData("EURUSD", new Symbol(Security.GenerateForex("EURUSD"), "EURUSD"))
      };
  }
  </code></pre>
  
  <p>2.X version creating exception and my tests are fail. Shortly exception telling that TestCaseData provider method must be static. Well, after mark method with static identifier test working correctly but this time my other test failing (before use static identifier it's not failing). Why my other test failing? Because it's reading a file from test directory and somehow test working before setup up fixture codes run and change test directory!</p>
  
  <p>Before use static identifier first SetUpFixture codes run and then tests code run. After use static identifier order changing my test that read file from test directory (which is Re-Sharper's temporary directory and not contain necessary file) run first after that SetUpFixture codes run. Any idea how all my tests to be successful?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Explain some units;</p>
  
  <ol>
  <li>I have Initialize.cs (part of my test assembly) which is responsible setup CurrentDirectory.</li>
  <li>I have Config.cs (part of my project infrastructure assembly) which is my project configuration file and it has public static readonly Setttings property which is reading configuration file from CurrentDirectory.</li>
  <li>I have ConfigTests.cs (part of my test assembly) which is contain some test methods for read/write Settings property.</li>
  </ol>
  
  <p>When i debug tests;</p>
  
  <ol>
  <li>Before use any static TestCaseSource, they are working below order;</li>
  </ol>
  
  <p>A. Initialize.cs => Setup method</p>
  
  <p>B. Config.cs => static Settings property getter method</p>
  
  <p>C. ConfigTests.cs => first test method</p>
  
  <p>So initialize working first others working later all tests successfully passing from test.</p>
  
  <ol start="2">
  <li>After use static TestCaseSource for inside other test file lets say OrdersTests.cs (excluded from project for first scenario after that included again), somehow working order is changing like below;</li>
  </ol>
  
  <p>A. Config.cs => static Settings property getter method</p>
  
  <p>B. OrdersTests.cs => static TestCaseSource method (not test method)</p>
  
  <p>C. Initialize.cs => Setup method</p>
  
  <p>D. ConfigTests.cs => first test method</p>
  
  <p>E. OrdersTests.cs => first test method</p>
  
  <p>So, my ConfigTests.cs tests failing because Initialize.cs working after Config.cs. I hope with this update my problem is more clear.</p>
  
  <p>Is this problem related NUnit or Resharper or V.Studio? I don't know and all i know is my successfully passing tests are failing now!</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>Chris,</p>
  
  <p>Yes you are right. I explore project in detail and i saw the problem is related that my project's some classes accessing to static Config class and it's static Settings property (before run test setup fixture method and even before static test case source method!). You talk about order of process of test methods; NUnit doing tests like your said, not like i said. But when i try to use your solution (set current directory before test case source) it's not working. Because of that i solve my problem in another way. I'm not happy but at least my test methods working now. Could you please tell me what are the technical reasons that run static test case methods before initialize/setup method? Is this because of NUnit or because of infrastructure of .Net Framework? I'm not fanatic about NUnit and/or TDD. I don't have deep knowledge about these concepts but it does not make sense to me: run any method before setup method.</p>
  
  <p>Thanks for your interest.</p>