public async Task Reading() { var m1 = new byte[] { 1, 2, 3, 4 }; var m2 = new byte[m1.Length]; var stream = new Substream(); stream.AddData(new byte[] { 1, 2 }); stream.AddData(new byte[] { 3, 4 }); stream.NoMoreData(); Assert.IsTrue(stream.CanRead); m2[0] = (byte)stream.ReadByte(); Assert.AreEqual(1, stream.Read(m2, 1, 1)); Assert.AreEqual(2, await stream.ReadAsync(m2, 2, 2)); CollectionAssert.AreEqual(m1, m2); Assert.AreEqual(-1, stream.ReadByte()); Assert.IsFalse(stream.CanRead); }
public void Reading_Empty() { var stream = new Substream(); var _ = Task.Run(async() => { await Task.Delay(100); stream.NoMoreData(); }); Assert.AreEqual(-1, stream.ReadByte()); }
public async Task Reading_Partial() { var m1 = new byte[] { 1, 2, 3, 4 }; var m2 = new byte[m1.Length]; var stream = new Substream(); stream.AddData(m1); stream.NoMoreData(); Assert.AreEqual(4, await stream.ReadAsync(m2, 0, 5)); CollectionAssert.AreEqual(m1, m2); Assert.AreEqual(-1, stream.ReadByte()); Assert.IsFalse(stream.CanRead); }