public async Task CancelPendingRead_CancelThenResumeReading_ReturnData() { // Arrange var testPipe = new Pipe(); await testPipe.Writer.WriteAsync(new byte[] { (byte)'A' }).AsTask().DefaultTimeout(); var r = new Base64PipeReader(testPipe.Reader); // Act 1 var readTask = r.ReadAsync().AsTask().DefaultTimeout(); r.CancelPendingRead(); var result = await readTask.DefaultTimeout(); // Assert 1 Assert.IsTrue(result.IsCanceled); // Act 2 r.AdvanceTo(result.Buffer.Start, result.Buffer.End); await testPipe.Writer.WriteAsync(new byte[] { (byte)'A', (byte)'=', (byte)'=' }).AsTask().DefaultTimeout(); result = await r.ReadAsync().AsTask().DefaultTimeout(); // Assert 2 CollectionAssert.AreEqual(Convert.FromBase64String("AA=="), result.Buffer.ToArray()); }
public async Task CancelPendingRead_CancelOnFirstRead_CancelResult() { // Arrange var testPipe = new Pipe(); var r = new Base64PipeReader(testPipe.Reader); // Act var readTask = r.ReadAsync().AsTask().DefaultTimeout(); r.CancelPendingRead(); var result = await readTask; // Assert Assert.IsTrue(result.IsCanceled); }
public async Task CancelPendingRead_CancelOnSecondRead_CancelResult() { // Arrange var testPipe = new Pipe(); await testPipe.Writer.WriteAsync(new byte[] { (byte)'a' }).AsTask().DefaultTimeout(); var r = new Base64PipeReader(testPipe.Reader); // Act var readTask = r.ReadAsync().AsTask().DefaultTimeout(); r.CancelPendingRead(); var result = await readTask; // Assert Assert.IsTrue(result.IsCanceled); }