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 = GenerateStre
Modernized and slightly modified version of the extension methods for ToStream
:
public static Stream ToStream(this string value) => ToStream(value, Encoding.UTF8);
public static Stream ToStream(this string value, Encoding encoding)
=> new MemoryStream(encoding.GetBytes(value ?? string.Empty));
Modification as suggested in @Palec's comment of @Shaun Bowe answer.