示例#1
0
 public async Task ComputeHashAsync_SupportsCancellation()
 {
     using (CancellationTokenSource cancellationSource = new CancellationTokenSource(100))
         using (PositionValueStream stream = new SlowPositionValueStream(10000))
             using (HashAlgorithm hash = new SummingTestHashAlgorithm())
             {
                 await Assert.ThrowsAnyAsync <OperationCanceledException>(
                     () => hash.ComputeHashAsync(stream, cancellationSource.Token));
             }
 }
示例#2
0
        public void ComputeHashAsync_Disposed()
        {
            using (PositionValueStream stream = new SlowPositionValueStream(10000))
                using (HashAlgorithm hash = new SummingTestHashAlgorithm())
                {
                    hash.Dispose();

                    Assert.Throws <ObjectDisposedException>(
                        () =>
                    {
                        // Not returning or awaiting the Task, it never got created.
                        hash.ComputeHashAsync(stream);
                    });
                }
        }