public void WriteMessage_Takes_A_Buffer_From_The_BufferManager()
        {
            HttpMessageEncoderFactory factory = new HttpMessageEncoderFactory();
            MessageEncoder encoder = factory.Encoder;

            HttpResponseMessage response = new HttpResponseMessage();
            response.Content = new ByteArrayContent(new byte[5] { 0, 1, 2, 3, 4 });
            HttpMessage message = new HttpMessage(response);

            MockBufferManager bufferManager = new MockBufferManager();
            ArraySegment<byte> buffer = encoder.WriteMessage(message, int.MaxValue, bufferManager);
            Assert.IsTrue(bufferManager.TakeBufferCalled, "HttpMessageEncoder.WriteMessage should have taken a buffer from the bufferManager.");
            Assert.AreSame(buffer.Array, bufferManager.BufferTaken, "HttpMessageEncoder.WriteMessage should have returned the array taken from the bufferManager.");
        }
        public void ReadMessage_Returns_The_Buffer_To_The_Buffer_Manager()
        {
            HttpMessageEncoderFactory factory = new HttpMessageEncoderFactory();
            MessageEncoder encoder = factory.Encoder;

            byte[] bytes = new byte[5] { 0, 1, 2, 3, 4 };
            ArraySegment<byte> buffer = new ArraySegment<byte>(bytes);

            MockBufferManager bufferManager = new MockBufferManager();
            HttpMessage message = encoder.ReadMessage(buffer, bufferManager, "someType/someSubType") as HttpMessage;
            Assert.IsTrue(bufferManager.ReturnBufferCalled, "HttpMessageEncoder.ReadMessage should have returned the buffer to the buffer manager.");
            Assert.AreSame(bytes, bufferManager.BufferReturned, "HttpMessageEncoder.ReadMessage should have returned the original buffer instance to the buffer manager.");
        }