Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are running automated <em>unit tests</em>, my advice is to remove any dependencies to your database, as there is no reason for you to test Entity Framework. What I would personally do is to hide my database layer behind some form of repository interface, and offer some mock implementations when running my tests, using some form of dependency injection strategy or factory pattern.</p> <p>If you are also running automated <em>integration tests</em> it might make more sense to involve the database. It might appear that your connection string is not present in the test project's configuration. I am not sure how you tell EF which connection string to use, but I suggest avoiding a direct dependency to a settings entry. </p> <p>If you use EF Code First you can supply the connection string as an argument to the base constructor of your DbContext class. You could for example put your connection string into a static property, and fetch it when instantiating your db context</p> <pre><code>public static class MyConnectionStringProvider { public static string ConnectionString{ get; set; } } public class MyDbContext : DbContext { public MyDbContext() : base(MyConnectionStringProvider.ConnectionString) { } } </code></pre> <p>Now, at some point in your app startup and test set up routines you can set the connection string. This allows you to control which connection string to use. </p> <p>For example, if you are running an azure web site you would typically get your connection string from the role configuration rather than an app.config file, in your Application_Start method. </p> <pre><code>MyConnectionStringProvider.ConnectionString = RoleEnvironment.GetConfigurationSettingValue("MyConnectionString") </code></pre> <p>In your test class, you could do something entirely different</p> <pre><code>MyConnectionStringProvider.ConnectionString = "[connectionstring to my test database]" </code></pre> <p>Finally, there might be some firewall quirks that needs to be sorted out, since you might need to add an exception in the SQL Azure servers firewall for the computer running the test. I'd contact MS Support about this if it turns out to be necessary.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload