Avoiding dispose of underlying stream
Posted
by danbystrom
on Stack Overflow
See other posts from Stack Overflow
or by danbystrom
Published on 2010-04-12T09:02:26Z
Indexed on
2010/04/12
10:33 UTC
Read the original article
Hit count: 312
I'm attempting to mock some file operations. In the "real" object I have:
StreamWriter createFile( string name )
{
return new StreamWriter( Path.Combine( _outFolder, name ), false, Encoding.UTF8 ) );
}
In the mock object I'd like to have:
StreamWriter createFile( string name )
{
var ms = new MemoryStream();
_files.Add( Path.Combine( _outFolder, name ), ms );
return new StreamWriter( ms, Encoding.UTF8 ) );
}
where _files is a dictionary to store created files for later inspection.
However, when the consumer closes the StreamWriter, it also disposes the MeamoryStream... :-(
Any thoughts on how to pursue this?
© Stack Overflow or respective owner