public void ReadBytes_FillBufferWithPartialCharacter() { // Reading a multi-byte character into a buffer that is too small requires us to buffer // the result from the text reader, since we're only returning part of a character. // So this test is to make sure we're doing that. // This character should be encoded into three bytes for UTF8. const string inputString = "☃"; Assert.AreEqual(3, Encoding.UTF8.GetBytes(inputString).Length); using (var stream = new TextReaderStream(new StringReader(inputString))) { var buffer = new byte[3]; int readCount = stream.Read(buffer, 0, 2); Assert.AreEqual(2, readCount); int secondReadCount = stream.Read(buffer, 2, 999); Assert.AreEqual(1, secondReadCount); var streamText = Encoding.UTF8.GetString(buffer); Assert.AreEqual(inputString, streamText); } }
public void Dispose_ThenReadThrowsObjectDisposedException() { var stream = new TextReaderStream(new StringReader(string.Empty)); stream.Dispose(); Assert.Throws <ObjectDisposedException>(() => stream.Read(new byte[10], 0, 10)); }