I have a project having more than one .exe and also having more than one .config files.The project is in .Net Framework and it’s windows application. I have built this project for Nunit Testing.I have to define some key in config file. So I want to know that how could I know that which config file is being used by Nunit? There is no app.config file.All config files having name other than app.config.
Share
Try getting the current
Configurationobject:Then the
config.FilePathwill tell you which .config file is loaded.Update:
The value returned from the
FilePathproperty is the default location for the current assembly. As the current assembly is loaded by NUnit, this will not be the location which is normally used by your application.To solve your problem, you could
Always load your configuration from a location which you provide:
Configuration config = ConfigurationManager.OpenExeConfiguration(path);Use NUnit to copy a test config file to the location you find in the file path:
File.Copy(testConfigFile, config.FilePath);Use NUnit to set up the key you want to test in the test itself:
ConfigurationManager.AppSettings.Add("key", "value");