public void TransformTest()
        {
            const string originalContent = "Original content";
            const string transformedContent = "Transformed content";
            Encoding encoding = Encoding.UTF8;
            byte[] originalBuffer = encoding.GetBytes(originalContent);
            string capturedContent = null;

            MemoryStream memoryStream = new MemoryStream();
            TransformableStream transformableStream = new TransformableStream(memoryStream, encoding);
            transformableStream.Transform += delegate(object sender, StreamTransformingEventArgs e) { e.TransformedContent = transformedContent; };
            transformableStream.Capture += delegate(object sender, StreamEventArgs e) { capturedContent = e.Content; };
            for(int i = 0; i < originalBuffer.Length; i++)
            {
                transformableStream.Write(originalBuffer, i, 1);
            }
            Assert.AreEqual(0, memoryStream.ToArray().Length);
            Assert.AreEqual(originalBuffer.Length, transformableStream.CapturedStream.ToArray().Length);
            transformableStream.Flush();
            Assert.AreEqual(0, memoryStream.ToArray().Length);
            Assert.AreEqual(originalBuffer.Length, transformableStream.CapturedStream.ToArray().Length);
            transformableStream.Close();
            Assert.AreEqual(transformedContent, encoding.GetString(memoryStream.ToArray()));
            Assert.AreEqual(transformedContent, capturedContent);
        }
 public void Flush_IfHasTransformEvents_ShouldNotCallFlushOfTheWrappedStream()
 {
     Mock<Stream> streamMock = new Mock<Stream>();
     streamMock.Verify(stream => stream.Flush(), Times.Never());
     TransformableStream transformableStream = new TransformableStream(streamMock.Object, Mock.Of<Encoding>());
     transformableStream.Transform += (sender, e) => { };
     transformableStream.Flush();
     streamMock.Verify(stream => stream.Flush(), Times.Never());
 }