public void TestLargeStreamCopy() { FakeRandomGenerator frg = new FakeRandomGenerator(); using (MemoryStream source = new MemoryStream(frg.Generate(1000000))) { using (MemoryStream destination = new MemoryStream()) { using (PipelineStream pipeline = new PipelineStream(new CancellationToken())) { Task producerTask = Task.Run(() => { source.CopyTo(pipeline); pipeline.Complete(); }); Task consumerTask = Task.Run(() => { pipeline.CopyTo(destination); }); Task.WaitAll(producerTask, consumerTask); } Assert.That(source.ToArray().IsEquivalentTo(destination.ToArray()), "The source and destination should be the same after passing through the pipeline."); } } }