locked
Error running Test:The parameter 'exePath' is invalid RRS feed

  • Question

  • I am developing an application with a data layer and writing tests for my business objects.

    The problem I'm experiencing is that I get the connection string from the configuration file like this:

    Configuration config = ConfigurationManager.OpenExeConfiguration("Application.exe");
    ConnectionStringsSection connectionStrings
    	= (ConnectionStringsSection)config.GetSection("connectionStrings");
    
    // Add the username and password to the connection string and save it
    string connectionString = String.Format("{0}user id={1};password={2}",
    	connectionStrings.ConnectionStrings["Plain"].ConnectionString,
    	username, password);
    
    // Save the encrypted connection string to the settings for future use
    connectionStrings.ConnectionStrings["Encrypted"].ConnectionString
    	= Encryption.EncryptData(connectionString);
    config.Save();
    ConfigurationManager.RefreshSection("connectionStrings");

    There is no problem when I run or debug the application, but when I run my tests I receive the error message "The parameter 'exePath' is invalid".

    Your help is really appreciated.

    PS: Running VS2008 on Vista Ultimate

    Fernando.

    Monday, May 10, 2010 3:51 PM

Answers

  • The only solution I could find, for those interested is to define a symbol in my data later project (in my case I used MSTEST) and use preprocessors to call the different configuration files.

    I created an app.config for the Test project with the exact same contents as my applications project and changed this line as follows:

    // Changed this line
    Configuration config = ConfigurationManager.OpenExeConfiguration("Application.exe");
    
    // To this
    #if !MSTEST
    Configuration config = ConfigurationManager.OpenExeConfiguration("Application.exe");
    #else
    Configuration config = ConfigurationManager.OpenExeConfiguration("Application.Tests.dll");
    #endif

    This way the tests work.

    Thank you,

    Fernando.

    • Marked as answer by JFercan Tuesday, March 29, 2011 11:38 PM
    Monday, May 10, 2010 5:08 PM