Search code examples
unit-testingenterprise-library

Using Test Projects and Enterprise Library: Where to put the ConectionStrings for the Test Class Lib Project?


I'm using the Microsoft.Practices.EnterpriseLibrary.Data library to establish a database connection. I suspect that that code is reading the ConnectionStrings section of the app.config file or web.config file, depending on the process that is running.

If I create a Test project to test my DAL, where would the ConnectionString go?

Since I am using Ent Lib, do I have any control over how that module determines where to find the ConnectionString?

Should I place my ConnectionString in a non standard XML file and have all Clients read from it?


Solution

  • It looking in your app.config/web.config.

    In your Data Access Layer you would have something like that:

    DatabaseFactory.CreateDatabase("MyConnectionString");
    

    In your app.config you should have your connectionStrings section. Connectionstring name should match to whatever you've specified in you DAL.

    If you want to setup a test environment, I would suggest to create a seperate config file for each environment. In your main config you would add an attribute to your ConnectionStrings (configSource="your config file name"), and in configuration manager you would specify, which config file goes for which configuration.

    Enterprise library doesn't give you any control to specify where to look for connection string.

    Hope this helps