title: Unit testing with Effort and SQL CE in parallel fails
body: <p>I'm evaluating unit tests using EF6 in combination with</p>
  
  <ul>
  <li><a href="http://effort.codeplex.com/">http://effort.codeplex.com/</a> and</li>
  <li>SQL CE Server (Local DB file)</li>
  </ul>
  
  <p><a href="http://www.codeproject.com/Articles/460175/Two-strategies-for-testing-Entity-Framework-Effort">http://www.codeproject.com/Articles/460175/Two-strategies-for-testing-Entity-Framework-Effort</a> was a quite good reference but now I'm stuck.</p>
  
  <p>I have 2 test projects (one for Effort and the other for SQL CE). If I'm running both separately everthing's fine. Running both in a row with the ReSharper test runner the last test project always fails. Either</p>
  
  <blockquote>
    <p>System.InvalidOperationException : The Entity Framework was already
    using a DbConfiguration instance before an attempt was made to add an
    'Loaded' event handler. 'Loaded' event handlers can only be added as
    part of application start up before the Entity Framework is used.</p>
  </blockquote>
  
  <p>or </p>
  
  <blockquote>
    <p>System.InvalidOperationException: The default DbConfiguration instance
    was used by the Entity Framework before an attempt was made to set an 
    instance of 'SqlCeConfiguration'.The 'SqlCeConfiguration' instance must
    be set at application start before using any Entity Framework features
    or must be registered in the application's config file.</p>
  </blockquote>
  
  <p>It's always the same. The successor inherits the DbConfiguration instance from the predecessor. <strong>How can I run both test projects / configuration without side effects?</strong></p>
  
  <p>Here's my <strong>DbContext</strong> class:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class DataContext : DbContext
  {
      public DataContext(string connectionString) : base(connectionString)
      { Configuration.LazyLoadingEnabled = false; }
  
      public DataContext(DbConnection connection) : base(connection, true)
      { Configuration.LazyLoadingEnabled = false; }
  }
  </code></pre>
  
  <p>That's the test fixture with <strong>Effort</strong>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[TestFixtureSetUp]
  public void TestFixtureSetup()
  {
      EffortProviderConfiguration.RegisterProvider();
      var connection = DbConnectionFactory.CreateTransient();
      var dbContext = new DataContext(connection);
      ...
  }
  </code></pre>
  
  <p>That's the test fixture with <strong>SQL CE</strong>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[TestFixtureSetUp]
  public void TestFixtureSetup()
  {
      const string filePath = @"LocalDb.sdf";
      var connectionString = string.Format("Data Source={0}; Persist Security Info=False;", filePath);
      DbConfiguration.SetConfiguration(new SqlCeConfiguration());
  
      var dbContext = new DataContext(connectionString);
      dbContext.Database.Create();
      ...
  }
  </code></pre>
  
  <p>and the my <strong>SqlCeConfiguration</strong>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class SqlCeConfiguration : DbConfiguration
  {
      public SqlCeConfiguration()
      {
          SetProviderServices(SqlCeProviderServices.ProviderInvariantName, SqlCeProviderServices.Instance);
          SetDefaultConnectionFactory(new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"));
      }
  }
  </code></pre>
  
  <p>Thank you so much!</p>
  
  <p>Marcel</p>