Specifying a file location in a Unit Test with Visual Studio tests - visual-studio-2010

I have a set of text files that I need to have a test take in and use the items for specific parts of some Unit tests I am writing. I have put a file path in my app.config of just: .\DataLists\
After I put that in there I added the items needed to add a custom section so it would then get that file path information. The problem I am having is this...it is not finding those lists in that location it is looking at some tmp folder instead. How do I specify a proper file location for this?

Have you tried using the DeploymentItemAttribute? link Use this on the test method(s) where you need access to your 'set' (folder I assume) of text files. The best practice here is to add the folder and files you want deployed to your project file and set them to 'Copy if newer' or 'Copy Always'.
You can also add the file(s) or folder to the Deployment section of the .testsettings configuration screen. In my experience this works better during Team Builds than the DeploymentItemAttribute route. In either case the 'Enable deployment' check box found in the .testsettings config screen must be checked.

Related

UWP Deploy Assets from arbitrary path

I want to avoid duplicating 400+ files in the Assets folder of my UWP App project folder. I want to tell VS to take files from an arbitrary location in my source tree, and use those in the Assets folder, preserving folder structure etc for deployment. I don't even mind setting the pathing manually in the project file properties if I must.
Is there a way to do this? The best I got was to right click on Assets\BlahFilter -> Add -> Existing Item. This results in the file appearing in the Solution treeview in the place I expect, but when deploying, the file appears in the root of AppX folder, ignoring any subfolder (filter) structure specified above.
I fixed this. You can use a "Custom Build Step" and treat the output as content. This will result in VS packaging that output directory's contents in the final AppX package. You can specify a folder, and all sub-folders will be automatically copied. The build command can be blank, or something innocuous like 'echo "blah"'

Upload a file through a microsoft webtest

I have a .webtest that I am intending to use to load test uploading a file to a website. I am using the webtest framework that is built into visual studio with the intention of running my larger scale tests from azure.
I created a new webtest and recorded the steps, including the file upload. This all recorded correctly, but the problem is that the File Upload Parameter was just recorded the filename (not the bytes). This means that the test needs to have access to the file that will be uploaded during running.
I also added the file to the project and set it to be content.
The problem is that the file isn't getting copied over during running. I found a blog post https://blogs.msdn.microsoft.com/edglas/2008/08/05/how-to-upload-a-file-in-a-web-test/ which appears to answer my question but the visual studio ui has changed and the option is no longer available.
I cannot use an absolute url c:\files\filename.docx because i need to run this from azure.
I also cannot post the file somewhere on the internet because it has to be a path, not a url.
I have posted a queston to the blog post, but it doesn't seem very active and am really at a lose for where to go from here.
TIA,
-Logan
The "Deployment" functionality shown in the last screenshot of Ed Glass's blog is now in the .testsettings files of the solution. (The blog shows a window with a "localtestrun.testrunconfig" file.) If you have more than one .testsettings file then ensure that the context menu of the correct file has the "Active load and web test settings" ticked.
In the deployment section of the .testsettings file, tick "Enable deployment" and add the directory or file(s) to be used in the tests. After running a test you should then find that the items have been copied into a subdirectory of the TestResults\{{name+date+time}} directory, as described in the blog.
New .testsettings files can be added to a solution as follows. From the context menu of the solution (the topmost item in Solution Explorer), select Add => New item => Test settings (from the left hand side of the "Add new item" window), then fill in the forms. New files can also be created via the "Save as" button in the test settings editor, but this requires a file to already be open.
When creating new .testsettings files I recommend changing the "Name" field in the "General" section to match the filename. Not doing so (after using "Save as") has left me confused because two or more files appear to have the same name. I normally have up to three .testsettings file in a solution: One for local use when developing tests. Another (often named "cloud" or "vsts") configured for cloud load testing with VSTS. The third version (often named "agent" or "remote") for use with controllers and agents.

Multiple build configuration in Advanced Installer

I am using Advanced Installer with Visual Studio 2010.
I managed to create an .aip project, but when I want to add the files from the relevant VS projects, I have to choose the exact location of these files.
I want to use more then one build configuration so I can use config transforms to change my .config files depend on the build configuration I choose.
This is a problem for me because when I compile in Debug the .exe & .dll files goes to bin\Debug, but when I compile in, lets say, Staging these files goes to bin\Staging.
How can I get Advanced Installer to get the right files, meaning get them from the target folder of the build configuration I chosen?
Advanced Installer does not support this by default, but with a little bit of tweaking you can get this working. Let me explain how:
the first requirement is to have your output folders generated by VS in the same parent folder, as you have them both placed in "bin\".
now you need to open your project in Advanced Installer GUI and do the following:
create two builds in Media page, called Debug and Staging
create a property called "Configuration" or what name would you like, from Install Parameters page
in the New Property dialog you will have options to set per-build values for your property. Set them to "Debug" and "Staging", i.e. the names of the folders created by VS
now go to File -> Options -> Path Variables and define a new path variable with your full path for the debug/staging, the one you current have in the project.
from the Home tab, in the toolbar, use the "Convert Paths" wizard and then save the project.
Now, it comes the tricky part, you will need to edit the project file in a text editor, like Notepad++, capable of saving the file in UTF-8 format. Once you open the file look for this XML node:
<COMPONENT cid="caphyon.advinst.msicomp.AppPathsComponent">
<ROW Name="BIN_DIR" Path="<your path>\bin\Debug" Type="2" Content="0"/>
You might have multiple variables here if you are already using this feature. You need to edit the value and replace "Debug" with "[|Configuration]".
Now you can save and build the project and it should pickup the correct files for each of the two builds.

Change default Add File path in Visual C++ 2010

When adding a new item in a Visual C++ project, the default path for the new file is the project path. Are there any per-project or per-solution settings that allow this default path to be modified?
For example, to add new files by default to a subdirectory of the project folder, or even to somewhere outside the project folder?
I understand that filters can be used to automatically organize files visually within the Solution Explorer based on file extension, but I would like to actually place the physical file in another location without the need to browse to it.
I'm using a Visual C++ project as a container to to manage and organize (filter) editing of runtime-compiled files, and don't want developers to accidentally place new files outside of the intended folder, nor do I want the project file to exist in this code folder.
I did discover that if you create a new file in a sub directory of the project, that the Add Item dialog will default to that path when you add another file during that session, but it does not persist the default to the project or solution for future sessions.
I don't believe there's anything built-in. Some commercial add ins make the behavior better. For example, Whole Tomato's Visual Assist X package always uses the same directory as the currently open file, IIRC.
There are a couple of open source add ins that let you modify the behavior. For example, this one.

How can I include .pdf files when I publish but not in a search and replace in visual studio?

More specifically my problem is if I include a pdf in my project and set its build action to content so it gets copied to the server when I publish, is there a way to exclude it from visual studios search and replace feature. Would a post build action be a solution to this? I just don't want anybody to do a global search and replace in my project and mess up the pdfs...
I know I just said a mouth full so let me know if you need clarification. Thanks!!!
If you look in the section headed "Find options" in the find dialog, there is an option titled "Look at these file types". If you qualify the type as *.cs, it will only look in files with that extension. You can also enter multiple file extensions. As long as you don't include pdf files in that filter, it will not apply to them. An alternative is to define a folder set to search in by clicking the ... next to the folder combo. Put your PDF files into a sub-directory of your project and exclude that folder from the folder set.
Additionally, as you have said, not including them in the project and using a post-build event to copy them to the output would also work.
I would qualify though that you are trying to solve a problem that shouldn't really be a problem. The onus is on the developer doing a find and replace to take care in doing so, and to not replace the contents of files they don't intend to change in the first place. Find an replace can be a dangerous tool.

Resources