I extend upon a legacy library which accesses files on the harddrive. I have such files as embedded resources in my unit test project.
I have ported parts of the library to accept streams, which allows me to use GetManifestResourceStream to pass my embedded resource to the legacy library. This works fine, but it is a slight hassle. And people maintaining those libraries don’t appreciate the “clutter” or having to publish new releases.
JustMock and TypeMock allows me to intercept the File.Open commmand, and I wish to pass the library a FileStream object, but how do I construct a FileStream Object from an Embedded Manifest Resource?
I could of course create a physical file, but I don’t wish to touch the file system while running tests.
I have cooked a sample based on the requirments you mentioned here. I used in memory stream for it but can done with embedded resource as well.
Since i am moking a mscorlib member and FileStream.Write is a instance call / not contains in the default set File, DateTime, FileInfo. I also added the following line during TestInitailization.
[Disclaimer i work for telerik]
Hope that helps,
Mehfuz