NUnit GUI Runner Multiple Configuration Files - nunit

I created a test project using a web.config file by renaming it to same name as the project, copying it to the bin folder and setting the Configuration File Name of the NUnit GUI runner to the name of my config file. Now I want to add more assemblies to this project but the problem here is each assembly has it's own web.config file.
How can I set the configuration files for the assemblies because I need to get my connection strings from these config files and considering when loading multiple assemblies they need to be in the same directory

While I feel that using config files for NUnit tests is a no-no (it's an integration test, in that case, I assume), there are various approaches you can try:
Put all your different connection strings under web.config in the connectionstrings section, with different keys. Access them via the System.Configuration classes.
For each project or DLL you can add an app.config file where you can store assembly specific information. This will be renamed as ProjectName.dll.config once compiled. Again you can access the contents of this file using System.Configuration
Create a new assembly that simply loads all these connection strings from a single file. And then access this assembly
If you are loading different web applications into the same directory (as you're saying you're accessing web.config files -- which means web applications) then you're making your life difficult. Each application has to have their own folder and virtual directory, and a web.config specific to only that application.

Related

Deploy ASP.NET MVC5 to IIS7 assembly not Found

Publishing a MVC5-Project with VisualStudio2015 works fine, all files are created in a folder and the .dll appears in the subfolder /bin. I set up the project with a new ApplicationPool in my IIS7, connect with the created folder and start it . Now I get the message
file or assembly not found at /MyFolder.
When I look at the temporary files of the application (path is given in the error message), there is none.
Why does the IIS not find the assemblies in the publishing Folder?
The first assembly that is mentioned in the error message is a custom assembly which is added to the References of the MVC5 project.
Should I add the custom assemblies via Web.Release.config? How?
solved the problem.
Open the ApplicationPool in the IIS7, then right-click on the name of the website -> advanced settings -> Enable-32-bit-Applications = true
[Could not load file or assembly or one of its dependencies. Access is denied. The issue is random, but after it happens once, it continues answered by Fragment

SSIS Build Error: Could not copy file to the deployment utility output directory

Problem
When attempting to build an SSIS package deployment utility by right-clicking on the solution and choosing "build", the build fails with an error message similar to the following:
Error 204 System.ApplicationException: Could not copy file
"MyPath\MyFile.dtsConfig" to the deployment utility output directory
"MyPath\bin\Deployment".
---> System.IO.IOException: The file 'MyPath\MyFile.dtsConfig' already exists.
This error can be caused by casing differences in the configuration file path. In some instances SSIS will treat c:\MyPath\MyFile.dtsConfig differently than c:\mypath\MyFile.dtsConfig.
I tested this with two different computers connected to the same TFS server. One pc had TFS mapped to C:\Packages. The other pc had TFS mapped to C:\packages. Creating a package and running on the first pc would create the deployment without any problems. Trying to create the deployment package on the second pc would result in the could not copy exception.
I manually edited the .dtsx file on the second pc. Changing the casing of the configuration file path under DTS:ConfigurationString= in the .dtsx file allowed the package to work correctly.
To get the package to work on both computers I updated the local path for TFS to have the same casing.
Cause
This is caused when SSIS is attempting to deploy multiple copies of the .dtsconfig file to the output directory. By default, SSIS will copy both all dependent files (including .dtsconfig files) and any files added to the solution under the Miscellaneous folder.
If you have added the file to your solution, but failed to repoint the Package Configuration to the new location, both copies will be deployed, and the build will fail.
This scenario can occur when you:
Create a package using a Package Configuration with a .dtsconfig file
Copy the package to a new directory without editing the Package Configuration
Add the configuration file to the project by right-clicking the solution, choosing Add --> New Item, and navigating to the file
Build the package.
Solution
To fix this, repoint your Package Configuration to the file underneath your solution directory. This can be done through the editor, or can be done by viewing the XML code of your package and manually editing the path of the file, such as with the following:
<DTS:Configurations>
<DTS:Configuration
DTS:ConfigurationString="MyPath\MySolution\MyFile.dtsConfig"
DTS:ConfigurationType="1"
DTS:CreationName=""
DTS:DTSID="{93222D3D-7AFF-1F2D-9UB8-B5E7X256BBE5}"
DTS:ObjectName="MyFile" />
</DTS:Configurations>
Further reading can be found here.

How exlude properties when building executable jar in Eclipse?

This question has been covered here before, but the only solutions I could find were in relation to a project using Ant or Maven. I am using neither. Here is the situation:
I have some application parameters in a properties file. This file is located in my Eclipse project (but in the src folder) and used when I run the application from Eclipse. In addition, I would like the application to also run as an executable jar file, in which case the user can provide the name of a properties file to use in a command line parameters.
The problem now is that the properties file from the project is always packaged into the executable jar and therefore the user is not able to easily modify the properties (yes, I know that (s)he could unzip the jar, but I want to avoid the extra steps).
How can I prevent the properties from being packages into the executable jar file?
Cheers,
Martin
Create a executable jar without properties file in it. Place both jar and properties file in a folder. Now add little code in your main program which should look for a properties file in the same folder and get the complete path of it. And then you can do something like this
System.getProperties().load(new FileInputStream(completepath));
So now your properties will be loaded into system properties with out affecting the actual system properties. You can access your properties by System.getProperty("Propertyname");
Hope this helps. Let me know if you have more questions.

Deploy war file with modifiable properties files

I am building a web service and am packaging it into a war file for deployment. Right now all of my config files (.properties and .xml) are being packaged into my .war file. This isn't going to work as some of these files will need to be modified for each individual installation. I know that some servlet containers will leave the .war files intact which would mean the config files would never be easily modified. My question is this: what is the best practice for deploying a .war file with these external config files? I'm thinking that the config files will need to be shipped separate from the .war file and placed into a directory that is in the classpath. Is there a default directory setup like this in Tomcat that these files can just be dropped into and my web service will be able to find without much trouble?
Maybe I shouldn't be using a war file for this setup? Maybe I should just be providing a zip file (with the same contents as the war file) and the deployment will simply be to extract the zip into the webapps directory?
I do not know any default directory in Tomcat to store configuration, my
attempts to solve the same issue have been :
1 - Move configuration to the DB and provide scripts or webpages to modify values.
2 - Have a script to deploy the war. The script would merge configuration from a user directory into web.xml or other deployed config files.
3 - Have webapps look first in a user directory for configuration and
if not found then look for configuration files deployed by the war.
Least favorite is 3 - it require all webapps to check two places for configuration and
you end up with two different xml files on the server with different values and it is not always clear which one is used.
Next favorite is 2 - the webapps can be written without knowledge of multiple config files, but you run into issue when someone does a deploy from Tomcat manager instead of using your script.
Favorite is 1. This just works in most cases. Problem is when you don't have a DB or
want to configure how you connect to the DB.
If having the file visible from all webapps is not an issue, you could put it $CATALINA_HOME/lib.
One solution is to modify property file after deployment of war file is to use ServletContext.getRealpath() method to get the real path means path of file in the server where it is deployed and then modify that file it will modify file in container only not the original file. So you need to backup it if it is important modification for you. So by this you do not need to redeploy war file as it is already modifying file from deployed container.
This solution can edit a file that is in webpages folder also from the java class.
If you want more description or how to do it then let me know i have did it.

MSTEST folder deployment question

Is there a way to preserve folder structure with MSTEST deployment?
I have a situation with some existing code where I have .config files in a subfolder (called "Configuration"). I can specify this folder using MSTEST deployment but, in it's infinite wisdom, MSTEST just copies the files from this folder to the run folder (TestResult\\Out), i.e. it does not create a subfolder called Configuration. This royally screws up the code and it fails. I don't really want to have to start using complicated pre-test scripts to create folders etc.
Any ideas gratefully received.
Matt
I think I had the same problem...
My tests used a folder called xsd and I wanted to deploy the folder to the test \OUT directory. When I did this, the files inside the xsd folder were copied to the test \OUT directory, but I wanted the folder xsd into the test \OUT directory...
To solve this I read this. (Wayback machine has an archive of this page here)
If you're using the DeploymentItem attribute, it takes a second argument for the name of the directory to copy the files into. If you use the same name as your folder it preserves everything.
To use your test case you'd do:
[DeploymentItem("Configuration", "Configuration")]
class TestClass
....
and it would work.
Yes, you can. read the article Do MSTest deployment items only work when present in the project test settings file?
It explains how to map deployment items.
In Visual Studio 2012 the output directory is the working directory which means that the DeploymentItem attribute isn't needed for the general case (where you don't have specific per-test or per-class deployment items). You can simply click Project | Show All Files and include the subfolder and files in Visual Studio with the 'Copy Always' or 'Copy if newer' attribute to your project and the files will be copied to your output directory with hierarchy intact. The same applies when running vstest.console.exe from the command line.
See here for more information about Deployment Items in Visual Studio 2012.