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.");
                }
            }
        }
        public void TestLargeWithVaryingChunkSizes()
        {
            FakeRandomGenerator frg = new FakeRandomGenerator();

            byte[] source = frg.Generate(500000);

            int[] chunkSizes = { 1, 2, 3, 5, 7, 11, 13, 17, 19, 64, 128, 256, 257, };

            using (MemoryStream destination = new MemoryStream())
            {
                using (PipelineStream pipeline = new PipelineStream(new CancellationToken()))
                {
                    Task producerTask = Task.Run(() =>
                    {
                        int i     = 0;
                        int total = 0;
                        while (total < source.Length)
                        {
                            int count = chunkSizes[i++ % chunkSizes.Length];
                            count     = total + count > source.Length ? source.Length - total : count;
                            pipeline.Write(source, total, count);
                            total += count;
                        }
                        pipeline.Complete();
                    });

                    Task consumerTask = Task.Run(() =>
                    {
                        byte[] read = new byte[17];
                        int count;
                        while ((count = pipeline.Read(read, 0, read.Length)) > 0)
                        {
                            destination.Write(read, 0, count);
                        }
                    });

                    Task.WaitAll(producerTask, consumerTask);
                }

                byte[] result = destination.ToArray();

                Assert.That(source.IsEquivalentTo(result), "The source and result should be the same after passing through the pipeline.");
            }
        }