Thus wrote Jon Skeet [C# MVP],
tc******@yahoo.com <tc******@yahoo.comwrote:
>Do you have a NUNIT code example of how you would read the config
file or the resource file?
I'm afraid I don't have time to come up with an example at the moment
- but have you tried it? Just call Assembly.GetManifestResourceStream
and use the returned stream as you would any other stream to load data
from.
May I help out :-)
I use this helper class to create and remove temporary files for unit tests.
One can use SetUp() to create a temporary file and TearDown() to remove it.
public static class TestUtility {
public static FileInfo CreateTestFile(string resourceName) {
FileInfo file = new FileInfo(Path.GetTempFileName());
Assembly assembly = Assembly.GetCallingAssembly();
Stream istream = assembly.GetManifestResourceStream(resourceName);
using(FileStream ostream = file.Open(FileMode.Create, FileAccess.Write))
{
byte[] buffer = new byte[0x2000];
int bytes;
while((bytes = istream.Read(buffer, 0, buffer.Length)) 0) {
ostream.Write(buffer, 0, bytes);
}
}
Console.WriteLine(">Created test file {0}", file.FullName);
return file;
}
public static void DeleteTestFile(FileInfo file) {
if(file != null) {
string fullName = file.FullName;
try {
file.Delete();
Console.WriteLine(">Deleted test file {0}", fullName);
}
catch(IOException ex) {
Console.WriteLine(">Cannot delete \"{0}\": {1}", fullName,
ex);
}
}
}
}
Cheers,
--
Joerg Jooss
ne********@joergjooss.de