public async Task TestReceive_FaultySourceConsume()
 {
     ITargetBlock<int> receiveTarget = null;
     var source = new DelegateReceivablePropagator<int, int>
     {
         LinkToDelegate = (target, options) => {
             receiveTarget = target;
             return new DelegateDisposable();
         },
         ConsumeMessageDelegate = delegate(DataflowMessageHeader messageHeader, ITargetBlock<int> target, out bool messageConsumed) {
             throw new FormatException();
         }
     };
     Task<int> receiveTask = source.ReceiveAsync();
     Assert.NotNull(receiveTarget);
     receiveTarget.OfferMessage(new DataflowMessageHeader(1), 1, source, consumeToAccept: true);
     await Assert.ThrowsAsync<FormatException>(() => receiveTask);
 }
 public async Task TestReceive_FaultySourceTryReceive()
 {
     var source = new DelegateReceivablePropagator<int, int>
     {
         TryReceiveDelegate = delegate(Predicate<int> filter, out int item) {
             throw new InvalidProgramException();
         }
     };
     Task<int> receiveTask = source.ReceiveAsync();
     await Assert.ThrowsAsync<InvalidProgramException>(() => receiveTask);
 }
 public void TestReceive_WellBehavingTarget()
 {
     ITargetBlock<int> receiveTarget = null;
     var source = new DelegateReceivablePropagator<int, int>
     {
         LinkToDelegate = (target, options) => {
             receiveTarget = target;
             return new DelegateDisposable();
         }
     };
     Task<int> receiveTask = source.ReceiveAsync();
     Assert.NotNull(receiveTarget);
     DataflowTestHelpers.TestOfferMessage_ArgumentValidation(receiveTarget);
     Assert.Throws<NotSupportedException>(() => { var ignored = receiveTarget.Completion; });
     receiveTarget.Fault(new Exception()); // shouldn't throw
 }