I am writing some unit tests in which I need a fake xml file. I can create that file and require it to be deployed with the unit tests, but experience shows that at my office it's a lot of headache. So I decided that the file will be created by UT's.
StreamWriter sw = new StreamWriter(testFileName);
sw.Write(contents);
sw.Close();
Now the problem is the contents string. It is virtually a long xml, something like this:
string contents =
@"<?xml version="1.0" encoding="windows-1251"?>
<blah>
~100 lines here
</blah> ";
I don't want this to be in the same file as the rest of the code. I want the string to be generated compile-time from a file.
In C++, I'd do this
string contents = "
#include "test.xml"
";
Is it possible somehow in C#?
Why don't you include it in a resource?
Use a resources (resx file) and add your xml file. Then you can access using MyNs.MyResources.MyXmlFile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With