How many times have you wanted to write a test which uses a real file (xml, xslx, xls, txt etc.) and got stumped as to how to include it in your project, and in source control AND then pop it in your c:\ temp to reference a filepath. You generally want to do this as this is what a user would be doing in a real life situation and is precidely what you want for integration and regression level tests.
Here’s what to do:
- Add your file to your solution/project (I like to create a solution folder, add the file there, and then link to this file in my project, again under a testresources folder or such*)
- On the properties for this file keep the build action as “None” and Copy to Output Directory to “Copy Always”
- In the project properties in the post-build event add the following line:
copy "$(TargetDir)\resources\*.xlsx" c:\temp\
- Build and hey presto! Your file is in your temp dir!