title: How can I unit test a TPL Dataflow pipeline?
body: <p>Given the following pipeline class I want to test the actual LinkTo(s) such that if I pass bad input into the DeserializeBlock I can check that DeserializeFailedBlock was called.  I'm looking for best practices on how to test that?</p>
  <pre><code>public class MyPipeline
  {
      public readonly TransformBlock&lt;byte[], PipelineMessage&gt; DeserializeBlock = new TransformBlock&lt;byte[], PipelineMessage&gt;(input =&gt; Deserialize(input));
              
      public readonly ActionBlock&lt;PipelineMessage&gt; DeserializeBlockFailed = new ActionBlock&lt;PipelineMessage&gt;(input =&gt; DeserializeFailed(input));
              
      public readonly TransformBlock&lt;PipelineMessage, PipelineMessage&gt; ValidateBlock = new TransformBlock&lt;PipelineMessage, PipelineMessage&gt;(input =&gt; Validate(input));
              
      public readonly ActionBlock&lt;PipelineMessage&gt; ValidateBlockFailed = new ActionBlock&lt;PipelineMessage&gt;(input =&gt; ValidateFailed(input));
              
      public readonly ActionBlock&lt;PipelineMessage&gt; PublishBlock = new ActionBlock&lt;PipelineMessage&gt;(input =&gt; Validate(input));
      
      public MyPipeline()
      {
             DeserializeBlock.LinkTo(ValidateBlock, message =&gt; message.IsValid)
             DeserializeBlock.LinkTo(DeserializeBlockFailed, message =&gt; !message.IsValid)
      
             ValidateBlock.LinkTo(PublishBlock, message =&gt; message.IsValid)
             ValidateBlock.LinkTo(ValidateBlockFailed, message =&gt; !message.IsValid)
      }
      
      public PipelineMessage Deserialize(byte[] message)
      {
      ...
      }
      
      public void DeserializeFailed(PipelineMessage message)
      {
      ...
      }
      
      public PipelineMessage Validate(PipelineMessage message)
      {
      ...
      }
      
      public void ValidateFailed(PipelineMessage message)
      {
      ...
      }
      
      public PipelineMessage Publish(PipelineMessage message)
      {
      ...
      }
  }
  </code></pre>