2

I'm creating SpecFlow tests for an application that uses an xml settings file (example, C:\ssis\mySettingsFile.xml) to run. In one test, I want to save the file to disk, and then add that file to my project resources and clean up the disk location. Then, another test will unpack the resource to a temporary directory and use it from there.

I'm clear about the unpacking part, but is there a way to programatically pack the file into a project resource rather than manually adding it to the project using the VS GUI and marking it as an embedded resource?

I know this is wrong, but I'm thinking something along the lines of:

string myPath = "C:\ssis\mySettingsFile.xml";
TestHelper.ResourceDirectory = "$\...\...\Project.Folder.Resources";
myResource = TestHelper.PackResource(myPath);
myResource.IsEmbeddedResource = true;

...where PackResource method saves the file to the project resources.

Thanks in advance!

Ryan Cox
  • 938
  • 1
  • 7
  • 22

1 Answers1

4

you can create a Resource Folder and add your xml to it. When you click on Properties of the project, there will be a Resources tab wherein you can see your file. To access the file, you can use ProjectNamespace.Properties.Resources.yourfilename.

HappyLee
  • 435
  • 4
  • 11
  • Thanks, but I need to specifically add it using C# in my test class because it doesn't exist in any state I want to save until after the test has run. I'll try to add an example of what I'm trying to do. – Ryan Cox Aug 01 '13 at 19:46
  • I found [this forum post]( http://stackoverflow.com/questions/6926378/how-do-i-replace-embedded-resources-in-a-net-assembly-programmatically) that seems to do what I am looking to do. However upon further research, it would probably be counter intuitive to the result I want/need. Since saving a file into my resources would change the state of the test each time it's run, it essentially invalidates the test. To keep a sterile test environment, I'll delete any temporary files that I unpack, and manually embed my files for the tests that require them as suggested above. Thanks! – Ryan Cox Aug 02 '13 at 02:14