title: Entity Framework Unit Test - The function evaluation requires all thread to run
body: <p>I'm trying to create a simple Unit test on a projet in order to test my connection to my database, but each time i run my test, the DbContext throw me the following error : The function requires all thread to run.</p>
  
  <p>Here my unit test :</p>
  
  <pre><code>[TestMethod]
          public void CanReadObjectFromContext()
          {
              using (var context = new DbAccess())
              {
                  var blogger = context.Set&lt;Blog&gt;().ToList();
                  Assert.IsTrue(blogger.Any());
              }
          }
  </code></pre>
  
  <p>Here my DbContext</p>
  
  <pre><code>public class DbAccess : BaseContext&lt;DbAccess&gt;
      {
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.Configurations.Add(new BlogConfiguration());
          }
  
          private void ApplyRules()
          {
              foreach (var entry in this.ChangeTracker.Entries().Where(e=&gt;e.Entity is IAuditInfo &amp;&amp; (e.State == EntityState.Added || e.State == EntityState.Modified)))
              {
                  var e = (IAuditInfo) entry.Entity;
                  if (entry.State == EntityState.Added)
                      e.CreatedOn = DateTime.Now;
  
                  e.ModifiedOn = DateTime.Now;
              }
          }
  
          public override int SaveChanges()
          {
              ApplyRules();
              return base.SaveChanges();
          }
      }
  </code></pre>
  
  <p>And my base class for my DbContext</p>
  
  <pre><code>public class BaseContext&lt;TContext&gt; : DbContext where TContext : DbContext
      {
          static BaseContext()
          {
              // On s'assure que le BdContext ne va pas faire d'action de modifciationsur notre base de données
              // Ici nous avons déjà une base de données existante
              Database.SetInitializer&lt;TContext&gt;(null);
          }
  
          protected BaseContext()
              : base(ConnectionStringName)
          {
  
          }
  
          public static string ConnectionStringName
          {
              get
              {
                  if (ConfigurationManager.AppSettings["ConnectionStringName"] != null)
                      return ConfigurationManager.AppSettings["ConnectionStringName"];
  
                  return "SqlConnection";
              }
          }
      }
  </code></pre>
  
  <p>Thank for your help.
  Anthony</p>