public async Task TestWriteArrays() { var impl = new DelayedContentOutputStream(); impl.Write(new byte[] { 1, 2 }); impl.Write(new byte[] { 3, 4 }); impl.Write(new byte[] { 5, 6 }); var actualBytes = await ToBytes_(impl); AssertSequence_(new byte[] { 1, 2, 3, 4, 5, 6 }, actualBytes); }
public async Task TestPosition() { var impl = new DelayedContentOutputStream(); var positionTask1 = impl.GetDelayedPosition(); impl.WriteDelayed( positionTask1.ContinueWith(pos => new[] { (byte)pos.Result }), Task.FromResult(1L)); impl.WriteByte(1); impl.Write(new byte[] { 2, 3 }); var positionTask2 = impl.GetDelayedPosition(); impl.WriteDelayed( positionTask2.ContinueWith(pos => new[] { (byte)pos.Result }), Task.FromResult(1L)); impl.WriteDelayed(Task.FromResult(new byte[] { 4, 5 })); impl.Write(new byte[] { 6, 7 }); var positionTask3 = impl.GetDelayedPosition(); impl.WriteDelayed( positionTask3.ContinueWith(pos => new[] { (byte)pos.Result }), Task.FromResult(1L)); impl.WriteByte(8); impl.WriteDelayed(Task.FromResult(new byte[] { 9, 10 })); var positionTask4 = impl.GetDelayedPosition(); impl.WriteDelayed( positionTask4.ContinueWith(pos => new[] { (byte)pos.Result }), Task.FromResult(1L)); var actualBytes = await ToBytes_(impl); AssertSequence_(new byte[] { 0, 1, 2, 3, 4, 4, 5, 6, 7, 9, 8, 9, 10, 13 }, actualBytes); }
public async Task TestWriteEverything() { var impl = new DelayedContentOutputStream(); impl.WriteByte(1); impl.Write(new byte[] { 2, 3 }); impl.WriteDelayed(Task.FromResult(new byte[] { 4, 5 })); impl.Write(new byte[] { 6, 7 }); impl.WriteByte(8); impl.WriteDelayed(Task.FromResult(new byte[] { 9, 10 })); var actualBytes = await ToBytes_(impl); AssertSequence_(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actualBytes); }
public async Task TestEmptySynchronousStream() { var impl = new DelayedContentOutputStream(); impl.Write(Array.Empty <byte>()); var actualBytes = await ToBytes_(impl); Assert.AreEqual(0, actualBytes.Length); }
public async Task TestLength() { var impl = new DelayedContentOutputStream(); var lengthTask = impl.GetDelayedLength(); impl.WriteDelayed( lengthTask.ContinueWith(length => new[] { (byte)length.Result }), Task.FromResult(1L)); impl.WriteByte(1); impl.Write(new byte[] { 2, 3 }); impl.WriteDelayed(Task.FromResult(new byte[] { 4, 5 })); impl.Write(new byte[] { 6, 7 }); impl.WriteByte(8); impl.WriteDelayed(Task.FromResult(new byte[] { 9, 10 })); var actualBytes = await ToBytes_(impl); AssertSequence_(new byte[] { 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actualBytes); }