title: C# MS Unit test call a method before validating Data source details
body: <p>I've a unit test function with <code>[DataSource("ConnectionStringName")]</code> and custom attribute function and a <code>[ClassInitialize]</code> decorated method which will execute before actual test method runs.</p>
  
  <p>In <code>[ClassInitialize]</code> decorated method I'm adding data source connection string of different types in the configuration file based on my custom attribute.</p>
  
  <p>The problem is before calling <code>[ClassInitialize]</code> method my unit test function verifying the connection string name <code>ConnectionStringName</code> is available in the configuration or not and thus giving exception like</p>
  
  <blockquote>
    <p><strong>'Data source 'ConnectionStringName' cannot be found in the test configuration settings'</strong></p>
  </blockquote>
  
  <p>before calling <code>[ClassInitialize]</code> decorated method, which is failing to update the connection string in configuration file.</p>
  
  <p>Any trick to make a call to the <code>[ClassInitialize]</code> decorated method, even connection string was not found in the configuration settings for any test method.</p>
  
  <p>Below is my code.</p>
  
  <pre class="lang-cs prettyprint-override"><code>[ClassInitialize]
  public static void TestSetup(TestContext context)
  {
      DataSourceConnectionHelper sourceConnectionHelper = new DataSourceConnectionHelper(typeof(AccountControllerTest), context.FullyQualifiedTestClassName, context.TestName);
      var status = sourceConnectionHelper.UpdateConnection();
  }
  
  [CsvDataConnection(@"DataSource\UserData.csv")]
  [DataSource("ConnectionStringName")]
  [TestMethod]        
  public void UserValidationTest()
  {
  }
  </code></pre>