public void TestChoose_FaultySource()
 {
     var source = new DelegateReceivablePropagator<int, int> {
         TryReceiveDelegate = delegate(Predicate<int> filter, out int item) {
             throw new FormatException();
         }
     };
     Task<int> t = DataflowBlock.Choose(source, i => { }, source, i => { });
     Assert.Throws<FormatException>(() => t.GetAwaiter().GetResult());
 }
 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 TestChoose_WellBehavingTarget()
 {
     ITargetBlock<int> chooseTarget = null;
     var source = new DelegateReceivablePropagator<int, int>
     {
         LinkToDelegate = (target, options) => {
             chooseTarget = target;
             return new DelegateDisposable();
         }
     };
     Task<int> chooseTask = DataflowBlock.Choose(source, i => { }, source, i => { });
     Assert.NotNull(chooseTarget);
     DataflowTestHelpers.TestOfferMessage_ArgumentValidation(chooseTarget);
     Assert.Throws<NotSupportedException>(() => { var ignored = chooseTarget.Completion; });
     chooseTarget.Fault(new Exception()); // shouldn't throw
 }
 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);
 }