public static void MemoryStream_LengthTest()
{
using (MemoryStream ms2 = new MemoryStream())
{
// [] Get the Length when position is at length
ms2.SetLength(50);
ms2.Position = 50;
StreamWriter sw2 = new StreamWriter(ms2);
for (char c = 'a'; c < 'f'; c++)
sw2.Write(c);
sw2.Flush();
Assert.Equal(55, ms2.Length);
// Somewhere in the middle (set the length to be shorter.)
ms2.SetLength(30);
Assert.Equal(30, ms2.Length);
Assert.Equal(30, ms2.Position);
// Increase the length
ms2.SetLength(100);
Assert.Equal(100, ms2.Length);
Assert.Equal(30, ms2.Position);
}
}