I need to write a unit test for a method that takes a stream which comes from a text file. I would like to do do something like this:
Stream s = GenerateStreamFromString("a,b \n c,d");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Don’t forget to use Using:
About the
StreamWriternot being disposed.StreamWriteris just a wrapper around the base stream, and doesn’t use any resources that need to be disposed. TheDisposemethod will close the underlyingStreamthatStreamWriteris writing to. In this case that is theMemoryStreamwe want to return.In .NET 4.5 there is now an overload for
StreamWriterthat keeps the underlying stream open after the writer is disposed of, but this code does the same thing and works with other versions of .NET too.See Is there any way to close a StreamWriter without closing its BaseStream?