views:

172

answers:

3

Here's the situation:

I've got a solution with multiple unit testing projects, each targeting a specific assembly in the application. These unit test projects require a set of App_Config* files in order to execute (i.e. connectionStrings.config, appSettings.config, etc). When I run the tests from within VS.NET using TD.NET or ReSharper, as expected the world is good, however, when I run my NAnt build scripts to execute the tests, my build output folder which contains all of the assemblies, test assemblies, etc, does not contain any of the associated App_config* files.

I tried setting all of the App_Config file properties to "Copy Always" which works fine when there is a single testing project within the solution i'm building, however when multiple projects are all within the same solution and all contain the same config file names with different settings, the world begins to fall apart.

What is the best way to handle this situation?

Thanks

A: 

Manually rename the app.config files to correspond with the name of the particular assembly it goes along with ("assembly1.dll.config", "assembly2.dll.config", etc). Do this in the projects themselves. This will disallow Visual Studio renaming the files itself. Next, copy them all over to the output directory with their individual varied names.

David Morton
The problem doesn't lie in the App.config itself (which is correctly renamed to assemblyname.config when compiled) its the related configuration files in the App_Config folder which are causing the problems but thanks for the attempted assist
A: 

In the app.config, instead of config sections themselves, put references to separate files using the configSource attribute.

  <appSettings configSource="Config\AppSettings.SupportTest.config" />
  <ConnectionConfig configSource="Config\DatabaseConnections.config" />
  <log4net configSource="Config\Log4Net.config" />

Then, have different config section files for each host, and in the app config for each test host change the indirect references to the appropriate file for each test host.

i.e., in the app.config for UnitTestHostA, put

  <appSettings configSource="Config\AppSettings.UnitTestHostA.config" />
  <ConnectionConfig configSource="Config\Connections.UnitTestHostA.config" />
  <log4net configSource="Config\Log4Net.config" />

and for UnitTestHostB, put

  <appSettings configSource="Config\AppSettings.UnitTestHostB.config" />
  <ConnectionConfig configSource="Config\Connections.UnitTestHostB.config" />
  <log4net configSource="Config\Log4Net.config" />
Charles Bretana
This is how we have it setup now but the problem is that both applications UnitTestHostA and UnitTestHostB require the same configSource files but in UnitTestHostA the file may have a property set to "A" and in UnitTestHostB the file the same property might get set to "B". I don't want to end up renaming the configuration files specific to each test app since this will cause major maintenance nightmares as new configuration files are added to the application itself. I would like to simply take the latest version of the configs from the app and drop them in the test assembly
A: 

Just in case anyone is interested in how I resolved this:

My resolution is closest to what Charles and David suggested regarding renaming my config files specific to the test assembly however instead of renaming each file, I opted for renaming the folder App_Config to [AssemblyName]_Config this way the amount of renaming I would have to do is very limited (in fact there is no other renaming to do).

Of course, I also had to do a find and replace in my main App.config file for all configSource="App_Config\" to configSource="[AssemblyName]_Config" (where [AssemblyName] is the name of the test assembly)